Qt 單擊任務欄圖標實現最小化


Qt中對於窗口邊框的設置一般用到setWindowFlags函數。

void setWindowFlags(Qt::WindowFlags type)

 

如果只setWindowFlags(Qt::FramelessWindowHint);
去掉邊框,此時會發現,當程序打開后,單擊任務欄的按鈕,會發現無法最小化,隱藏窗口。
解決的方法是:
setWindowFlags(Qt::Window|Qt::FramelessWindowHint |Qt::WindowSystemMenuHint|Qt::WindowMinimizeButtonHint|Qt::WindowMaximizeButtonHint);
再次測試,發現邊框去掉了,而且鼠標點擊任務欄圖標,也可以顯示和隱藏窗口了。
 
附:
Qt::Widget

This is the default type for QWidget.

Widgets of this type are child widgets if they have a parent,and independent(獨立的) windows if they have no parent.

See also Qt::Window and Qt::SubWindow.

Qt::Window

Indicates(標志,象征) that the widget is a window.

Usually with a window system frame and a title bar,irrespective of (不管)whether the widget has a parent or not.

Note that it is not possible to unset this flag if the widget does not have a parent.

Qt::Dialog Indicates that the widget is a window that should be decorated as a dialog (i.e., typically no maximize or minimize buttons in the title bar). This is the default type for QDialog. If you want to use it as a modal dialog, it should be launched from another window, or have a parent and used with the QWidget::windowModality property. If you make it modal, the dialog will prevent other top-level windows in the application from getting any input. We refer to a top-level window that has a parent as a secondary window.
Qt::FramelessWindowHint

Produces a borderless window.

The user cannot move or resize a borderless window via the window system.

On X11, the result of the flag is dependent on the window manager and its ability to understand Motif and/or NETWM hints. Most existing modern window managers can handle this.

Qt::CustomizeWindowHint Turns off the default window title hints.
Qt::WindowTitleHint Gives the window a title bar.
Qt::WindowSystemMenuHint

Adds a window system menu, and possibly a close button (for example on Mac).

 If you need to hide or show a close button, it is more portable to use WindowCloseButtonHint.

Qt::WindowMinimizeButtonHint

Adds a minimize button.

On some platforms this implies Qt::WindowSystemMenuHint for it to work.

Qt::WindowMaximizeButtonHint

Adds a maximize button.

On some platforms this implies Qt::WindowSystemMenuHint for it to work.

Qt::WindowMinMaxButtonsHint

Adds a minimize and a maximize button.

On some platforms this implies Qt::WindowSystemMenuHint for it to work.

Qt::WindowCloseButtonHint

Adds a close button.

 On some platforms this implies Qt::WindowSystemMenuHint for it to work.

 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM