記錄一下windowFlags各種標志位的樣式和用法,
代碼:
1 #include "qtwindowflagstest.h" 2 #include <QtWidgets/QApplication> 3 #include <QStatusBar> 4 #include <QObject> 5 6 int main(int argc, char *argv[]) 7 { 8 QApplication a(argc, argv); 9 QtWindowFlagsTest w; 10 w.setGeometry(10, 30, 200, 200); 11 w.statusBar()->showMessage(QObject::tr("Normal")); 12 w.show(); 13 14 //只有一個關閉按鈕 15 QtWindowFlagsTest w2; 16 w2.setGeometry(225, 30, 200, 200); 17 w2.setWindowFlags(Qt::WindowCloseButtonHint); 18 w2.statusBar()->showMessage("Qt::WindowCloseButtonHint"); 19 w2.show(); 20 21 //像對話框一樣,有個問號和關閉按鈕 22 QtWindowFlagsTest w3; 23 w3.setGeometry(440, 30, 200, 200); 24 w3.setWindowFlags(Qt::WindowContextHelpButtonHint); 25 w3.statusBar()->showMessage("Qt::WindowContextHelpButtonHint"); 26 w3.show(); 27 28 //標題欄也沒有 按鈕也沒有 在那里出現就站在那里不到,也不能移動和拖到,任務欄右擊什么也沒有,任務欄窗口名也沒有,但是可以從任務管理器里關閉 29 QtWindowFlagsTest w4; 30 w4.setGeometry(655, 30, 200, 200); 31 w4.setWindowFlags(Qt::CustomizeWindowHint); 32 w4.statusBar()->showMessage("Qt::CustomizeWindowHint"); 33 w4.show(); 34 35 //窗口只有一個關閉按鈕 36 QtWindowFlagsTest w5; 37 w5.setGeometry(870, 30, 200, 200); 38 w5.setWindowFlags(Qt::WindowTitleHint); 39 w5.statusBar()->showMessage("Qt::WindowTitleHint"); 40 w5.show(); 41 42 //只有一個關閉按鈕 43 QtWindowFlagsTest w6; 44 w6.setGeometry(1085, 30, 200, 200); 45 w6.setWindowFlags(Qt::WindowSystemMenuHint); 46 w6.statusBar()->showMessage("Qt::WindowSystemMenuHint"); 47 w6.show(); 48 49 //最小化按鈕不可用 50 QtWindowFlagsTest w7; 51 w7.setGeometry(1300, 30, 200, 200); 52 w7.setWindowFlags(Qt::WindowMaximizeButtonHint); 53 w7.statusBar()->showMessage("Qt::WindowMaximizeButtonHint"); 54 w7.show(); 55 56 //還原按鈕不可用 57 QtWindowFlagsTest w8; 58 w8.setGeometry(1515, 30, 200, 200); 59 w8.setWindowFlags(Qt::WindowMinimizeButtonHint); 60 w8.statusBar()->showMessage("Qt::WindowMinimizeButtonHint"); 61 w8.show(); 62 63 //窗口沒有按鈕但是有標題欄 任務里什么也看不到 64 QtWindowFlagsTest w9; 65 w9.setGeometry(2, 238, 200, 200); 66 w9.setWindowFlags(Qt::SubWindow); 67 w9.statusBar()->showMessage("Qt::SubWindow"); 68 w9.show(); 69 70 //沒有顯示在桌面也沒在任務。但是任務管里器里還有 71 QtWindowFlagsTest w10; 72 w10.setGeometry(217, 238, 200, 200); 73 w10.setWindowFlags(Qt::Desktop); 74 w10.statusBar()->showMessage("Qt::Desktop"); 75 w10.show(); 76 77 //標題欄也沒有 按鈕也沒有 在那里出現就站在那里不到,也不能移動和拖到,任務欄右擊什么也沒有,任務欄窗口名也沒有, 但是可以從任務管理器里關閉 78 QtWindowFlagsTest w11; 79 w11.setGeometry(432, 238, 200, 200); 80 w11.setWindowFlags(Qt::SplashScreen); 81 w11.statusBar()->showMessage("Qt::SplashScreen"); 82 w11.show(); 83 84 //標題欄也沒有 按鈕也沒有 在那里出現就站在那里不到,也不能移動和拖到,任務欄右擊什么也沒有,任務欄窗口名也沒有, 但是可以從任務管理器里關閉 頂層窗口 一直都是在最上面 85 QtWindowFlagsTest w12; 86 w12.setGeometry(647, 238, 200, 200); 87 w12.setWindowFlags(Qt::ToolTip); 88 w12.statusBar()->showMessage("Qt::ToolTip"); 89 w12.show(); 90 91 //有一個小小的關閉按鈕,但是好像不能真正的關閉 92 QtWindowFlagsTest w13; 93 w13.setGeometry(862, 238, 200, 200); 94 w13.setWindowFlags(Qt::Tool); 95 w13.statusBar()->showMessage("Qt::Tool"); 96 w13.show(); 97 98 return a.exec(); 99 }
結果:

