2013-07-07 12 views

回答

18

你沒有。該文檔是相當清楚的:

的QInputDialog類提供了一個簡單方便的對話框,獲得來自用戶的 值。

如果您想要多個值,請創建一個QDialog派生類,從頭開始,使用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,我需要但找不到... –