【发布时间】:2013-01-20 21:39:36
【问题描述】:
这个问题很简单。是否可以显示QDialog 或QMessageBox 而无需在任务栏中为其创建选项卡?我尝试使用 exec()、show()、更改模态值,但选项卡始终处于打开状态。
【问题讨论】:
标签: windows qt qdialog qmessagebox
这个问题很简单。是否可以显示QDialog 或QMessageBox 而无需在任务栏中为其创建选项卡?我尝试使用 exec()、show()、更改模态值,但选项卡始终处于打开状态。
【问题讨论】:
标签: windows qt qdialog qmessagebox
您需要为QMessageBox指定父窗口:
QApplication a(argc, argv);
qt_test_dialog w;
w.show();
// with additional button
// QMessageBox box(QMessageBox::Information, "Title", "Hello there!", QMessageBox::Ok);
// without additional button!
QMessageBox box(QMessageBox::Information, "Title", "Hello there!", QMessageBox::Ok, &w);
或者简单地说:
QMessageBox box(&w);
box.setText("Hello");
box.exec();
注意,父参数甚至可以为空QWidget:
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
// plain wrong (you will not be able to exit application) - but it demonstrates
// the case
QMessageBox box(new QWidget());
box.setText("Hello");
box.exec();
return a.exec();
}
【讨论】: