2013-07-07 32 views

Trả lời

18

Bạn không. Các tài liệu là khá rõ ràng:

các QInputDialog lớp cung cấp một hộp thoại thuận tiện đơn giản để có được một giá trị đơn từ người dùng.

Nếu bạn muốn có nhiều giá trị, hãy tạo lớp bắt nguồn QDialog từ đầu với 4 trường nhập.

Ví dụ:

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

Là nó có thể có các trường đầu vào và nhãn trong hộp thoại? –

+0

@Gowtham Tôi đã thêm một ví dụ vào câu trả lời của mình. – alexisdm

+0

Rất cám ơn vì đã đề cập đến QDialogButtonBox, những gì tôi cần nhưng không thể tìm thấy ... –