標準入力ボックスを使用---Qt

2811 ワード

void InputDialog::slotName()
{
    bool ok;
    QString name = QInputDialog::getText(this,tr("User Name"), tr("Please input new name:"), QLineEdit::Normal,nameLabel->text(),&ok);
    if(ok && !name.isEmpty())
    {
        nameLabel->setText(name);
    }
}

void InputDialog::slotAge()
{
	bool ok;
	//QString age = QInputDialog::getText(this, tr("User Age"),tr("Please input new age:"), QLineEdit::Normal,ageLabel->text(),&ok);
	int age = QInputDialog::getInteger(this, tr("User Age"),tr("Please input new age:"),ageLabel->text().toInt(), 0 , 150, 1, &ok);
	if(ok)
	{
		ageLabel->setText(QString(tr("%1")).arg(age));
	}
}

void InputDialog::slotSex()
{
    QStringList list;
    list << tr(" ") << tr(" ");
    bool ok;
    QString sex = QInputDialog::getItem(this, tr("Sex"), tr("Please select sex:"),list,0,false,&ok);
    if(ok)
    {
        sexLabel->setText(sex);
    }
}

void InputDialog::slotStature()
{
    bool ok;

   // QString stature = QInputDialog::getText(this,tr("User Stature"),tr("Please input number:"),QLineEdit::Normal, statureLabel->text(),&ok);
    double stature =QInputDialog::getDouble(this, tr("User Stature"),tr("Please input number:"), statureLabel->text().toDouble(), 140.0,200.0,1 , &ok);
    if(ok)
    {
        statureLabel->setText(QString(tr("%1")).arg(stature));
    }
}

QString QInputDialog::getText ( QWidget * parent, const QString & title, const QString & label, QLineEdit::EchoMode mode = QLineEdit::Normal, const QString & text = QString(), bool * ok = 0, Qt::WindowFlags flags = 0 )1番目のパラメータ:parentが標準入力ダイアログの親ウィンドウ2番目のパラメータ:標準入力ダイアログのタイトル名3番目のパラメータ:標準入力ダイアログのラベルプロンプト4番目のパラメータ:標準入力ダイアログの入力モード5番目のパラメータ:標準文字列入力ダイアログのポップアップ時にQLineEditコントロールにデフォルトで表示される文字6番目のパラメータ:ok標準入力ダイアログを示すボタンがトリガーされ、okがtrueの場合、ユーザーがOk(OKボタン)をクリックし、Cancelボタンをクリックしたことを示す.okはfalseの7番目のパラメータである.標準入力ダイアログのフォーム表示QStringを示す QInputDialog::getItem ( QWidget * parent, const QString & title, const QString & label, const QStringList & items, int current = 0, booleditable = true, bool * ok = 0, Qt::WindowFlags flags = 0 )
double QInputDialog::getDouble ( QWidget * parent, const QString & title, const QString & label, double value = 0, double min = -2147483647, double max = 2147483647, int decimals = 1, bool * ok = 0, Qt::WindowFlags flags = 0 ) int QInputDialog::getInteger ( QWidget * parent, const QString & title, const QString & label, int value = 0, int min = -2147483647, int max = 2147483647, int step = 1, bool * ok = 0, Qt::WindowFlags flags = 0)step QSpinBoxコントロールのステップ値decimalsをQSpinBoxコントロールのステップ値として指定