3
問題很簡單。是否可以顯示QDialog
或QMessageBox
而不在任務欄中創建選項卡?我嘗試使用exec(),show(),改變模態的值,但該標籤始終打開。QDialog沒有任務欄中的任務欄
問題很簡單。是否可以顯示QDialog
或QMessageBox
而不在任務欄中創建選項卡?我嘗試使用exec(),show(),改變模態的值,但該標籤始終打開。QDialog沒有任務欄中的任務欄
你需要指定父窗口爲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();
}
什麼絕qt_test_dialog是?只是一個自定義的QWidget?你可以請詳細解釋一下嗎? –
@AndreyChernukha Chernukha在我的情況下,這是一個簡單的QMainWindow子類(由嚮導生成),但它可以是自定義的QWidget等。 –
@AndreyChernukha請參閱我的編輯以獲取更多說明。 –