问题很简单。是否可以在不在任务栏中创建标签的情况下显示QDialog
或QMessageBox
?我尝试使用exec(),show(),更改模态的值,但选项卡始终打开。
答案 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();
}