2013-07-07 25 views

答えて

18

あなたはしません。ドキュメントはかなり明確である:

QInputDialogクラスは、ユーザーから 単一値を取得するには、簡単な便利なダイアログを提供します。

複数の値が必要な場合は、入力フィールドが4つのの派生クラスを最初から作成します。例えば

QDialog dialog(this); 
// Use a layout allowing to have a label next to each field 
QFormLayout form(&dialog); 

// Add some text above the fields 
form.addRow(new QLabel("The question ?")); 

// Add the lineEdits with their respective labels 
QList<QLineEdit *> fields; 
for(int i = 0; i < 4; ++i) { 
    QLineEdit *lineEdit = new QLineEdit(&dialog); 
    QString label = QString("Value %1").arg(i + 1); 
    form.addRow(label, lineEdit); 

    fields << lineEdit; 
} 

// Add some standard buttons (Cancel/Ok) at the bottom of the dialog 
QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, 
          Qt::Horizontal, &dialog); 
form.addRow(&buttonBox); 
QObject::connect(&buttonBox, SIGNAL(accepted()), &dialog, SLOT(accept())); 
QObject::connect(&buttonBox, SIGNAL(rejected()), &dialog, SLOT(reject())); 

// Show the dialog as modal 
if (dialog.exec() == QDialog::Accepted) { 
    // If the user didn't dismiss the dialog, do something with the fields 
    foreach(QLineEdit * lineEdit, fields) { 
     qDebug() << lineEdit->text(); 
    } 
} 
+0

がダイアログボックスに入力フィールドとラベルを持っていることができましたか? –

+0

@Gowtham私は私の答えに例を追加しました。 – alexisdm

+0

QDialogBu​​ttonBoxに言及してくれてありがとうございました。私が必要でしたが見つかりませんでした... –

関連する問題