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

Stella981
• 阅读 687

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.

点赞
收藏
评论区
推荐文章
Wesley13 Wesley13
2年前
visualize_object_model_3d显示3维图像的问题
原问题:我把halcon代码导出成C代码。并在QT中调用。其中用到了visualize\_object\_model\_3d但是,目前只能单独弹出一个窗口来显示3维图像,不能在QT的控件框中显示。像这样单独在一个窗口中显示,是可以的。!Halcon与QT混合编程CQT中使用visualize_object_model_3d显示
Wesley13 Wesley13
2年前
Qt5下OpenGL程序的新写法
在Qt5中,引入了QOpenGL\系列类,以取代Qt4时代的QGL\系列类。下面是从Qt5例子中抠出的两种OpenGL程序模板,方便参考。第一种写法:ifndefTRIANGLEWINDOW_HdefineTRIANGLEWINDOW_Hinclude<QWindow
Stella981 Stella981
2年前
QT中QString与string的转化,解决中文乱码问题
在QT中,使用QString输出到控件进行显示时,经常会出现中文乱码,网上查了一圈,发现大部分都是针对QT4增加4条语句:</spancppviewplaincopyQTextCodeccodecQTextCodec::codecForName("UTF8");QTextCo
Stella981 Stella981
2年前
QT软件的安装与使用(Win7与Ubuntu20.04)
本文介绍QT软件的下载与安装。一、下载QT软件可以从QT官网下载安装,下载网址为:http://download.qt.io/archive/qt/(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Fdownload.qt.io%2Farchive%2Fqt%2F)。当前最新
Stella981 Stella981
2年前
QT中手动释放堆中的对象(new 出来的)
Qt内存自动释放有两个前提条件:1.必须是QObject的派生类2.必须指定了parent对象即:Qt中父亲被删除的时候会自动销毁他的孩子。所以如果New出来的并且没有父亲。那么则需要手动删除它。需要,不然那块空间就一直占用了QLabellbnewQLabel();delete(lb);if(lbN
Stella981 Stella981
2年前
Qt编写数据可视化大屏界面电子看板3
一、前言能够新建布局,也是数据可视化大屏界面电子看板系统中的必备功能之一,新建布局这样的功能一般做到右键菜单中,单击新建布局菜单,弹出输入框要求输入新的布局的名称,为了更符合国情,直接支持中文名称,保存成配置文件直接中文名称命名,这样方便用户理解,Qt5以来对乱码的问题解决的就比较好了,不像Qt4时代稍不留神就乱码了,Qt5只要保证源码文件ut
Wesley13 Wesley13
2年前
LGPL 协议详解
Qt有两个许可证:LGPL和商业协议。这两个协议在现在的Qt版本中的代码是完全一致的(潜在含义是,Qt的早期版本,商业版的Qt通常包含有一些开源版本所没有的库,比如QtSingleApplication这个库)。所以现在对于普通开发人员和部分商业公司来说,使用LGPL版本的Qt可以节省很大的开销。这两个版本最大的区别在于,前者是免费
贾蓁 贾蓁
4个月前
明仕强 Qt高级开发视频
download》http://quangneng.com/4329/什么是Qt高级开发Qt高级开发是指使用Qt框架进行的高级应用程序开发,通常涉及到更复杂的界面设计、多线程、网络编程、数据库访问等高级技术。Qt是一个跨平台的应用程序开发框架,它提供了一套
乐和 乐和
2个月前
QT游戏开发入门到实战课堂视频精讲
QT游戏开发入门到实战课堂视频精讲download》chaoxingit.com/4854/QT游戏开发入门到实战:从零到一一、引言QT是一个强大的跨平台应用程序开发框架,它提供了丰富的库和工具,使得开发者可以轻松地创建各种类型的应用程序,包括游戏。QT游
程昱 程昱
2个月前
明仕强 Qt高级开发视频
明仕强Qt高级开发视频download》quangneng.com/4329/Qt哪个版本最好用Qt是一个开源的跨平台应用框架,广泛用于开发GUI程序。选择哪个版本的Qt最好用,取决于你的具体需求和目标平台。以下是一些近期的信息和观点:Qt5.15:这个版