Qt 单击任务栏图标实现最小化

Posted granx

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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.

 
 

以上是关于Qt 单击任务栏图标实现最小化的主要内容,如果未能解决你的问题,请参考以下文章

当用户在 Qt 应用程序中单击任务栏/停靠图标时获取事件或通知

qt中如何实现界面最小化时呈现收缩形式

请问怎样使程序在最小化后图标放在任务栏的托盘上?

C#实现无标题栏窗体点击任务栏图标正常最小化或还原的解决方法

带有操作栏图标单击的 NavigationUI 导致片段淡入淡出

实现点击任务栏图标显示或隐藏窗体