Qt--浮动子窗口

子窗口在父窗口上方浮动显示,点击父窗口,子窗口不会被父窗口覆盖,有如下3种方法:

1、继承自QDialog,使用show()方法显示窗口。

dialog->show();

2、继承自QWidget,设置窗口标志Qt::Tool。

widget->setWindowFlags(Qt::Tool);

3、继承自QWidget,设置窗口标志Qt::WindowStaysOnTopHint。这个标志是对于所有程序的窗口都置顶。也就是说其他程序打开后也是会被置顶的窗口所遮盖。

widget->setWindowFlags(Qt::WindowStaysOnTopHint);
//或者同时设置两个
widget->setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);

下方摘自qt是说明文档:
Qt::Tool是一个工具窗口,有父窗口时会一直置于父窗口的上方。如果没有父窗口时可以设置Qt::WindowStaysOnTopHint标志。

ConstantValueDescription
Qt::ToolPopup | DialogIndicates that the widget is a tool window. A tool window is often a small window with a smaller than usual title bar and decoration, typically used for collections of tool buttons. If there is a parent, the tool window will always be kept on top of it. If there isn’t a parent, you may consider using Qt::WindowStaysOnTopHint as well. If the window system supports it, a tool window can be decorated with a somewhat lighter frame. It can also be combined with Qt::FramelessWindowHint. On macOS, tool windows correspond to the NSPanel class of windows. This means that the window lives on a level above normal windows making it impossible to put a normal window on top of it. By default, tool windows will disappear when the application is inactive. This can be controlled by the Qt::WA_MacAlwaysShowToolWindow attribute.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值