任务栏中没有选项卡的QDialog

时间:2013-02-05 20:33:37

标签: windows qt qdialog qmessagebox

问题很简单。是否可以在不在任务栏中创建标签的情况下显示QDialogQMessageBox?我尝试使用exec(),show(),更改模态的值,但选项卡始终打开。

1 个答案:

答案 0 :(得分:3)

您需要为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();

请注意,parent参数甚至可以为空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();
}