Qt实现窗体无边框,并且点击windows任务栏图标可以最小化

本文介绍了Qt中如何使用setWindowFlags函数去除窗口边框,并保持窗口可最小化和隐藏的功能。通过设置不同的标志,可以实现无边框窗口的同时保留系统菜单、最小化和最大化按钮等功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Qt中对于窗口边框的设置一般用到setWindowFlags函数。

void setWindowFlags(Qt::WindowFlags type)

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::DialogIndicates 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::CustomizeWindowHintTurns off the default window title hints.
Qt::WindowTitleHintGives 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.

如果只setWindowFlags(Qt::FramelessWindowHint);
去掉边框,此时会发现,当程序打开后,单击任务栏的按钮,会发现无法最小化,隐藏窗口。
解决的方法是:
setWindowFlags(Qt::Window|Qt::FramelessWindowHint |Qt::WindowSystemMenuHint|Qt::WindowMinimizeButtonHint|Qt::WindowMaximizeButtonHint);
再次测试,发现边框去掉了,而且鼠标点击任务栏图标,也可以显示和隐藏窗口了。
 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值