关于Qt::Tool属性在部分Mac上不生效的问题

1 篇文章 0 订阅

        今天收到一个BUG,部分苹果用户接受不到新消息弹窗,我的新消息弹窗设置了Qt::Popup属性和Qt::Tool属性,其中Qt::Popup属性在Windows平台上会使窗口在右下方弹出 ,在Macos上会使窗口在右上方弹出,测试人员反馈M1芯片的Mac用户表示正常,其他非M1芯片的Mac用户就是弹不出消息提示窗口。

        仔细阅读帮助文档,其中有这么一句话,如下:

        Indicates 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.

        其中在Mac系统的默认情况下,窗口处于非活动状态时,工具窗口将消失,可以由Qt::WA_MacAlwaysShowToolWindow这一属性来控制,无论时隐藏进程序坞还是缩小窗口,Qt::Tool这一属性都会生效。

如果 Qt::WindowTaskbarButtonHint 属性在你使用的 Qt 版本中不可用,可以考虑使用 Qt::Tool 属性来实现窗口分开的效果。Qt::Tool 属性将窗口转换为工具栏窗口,可以在任务栏中分别显示每个窗口的图标和标题。 具体实现方法如下: 1. 在需要设置的窗口类的构造函数中,通过 setWindowFlags 函数设置窗口属性。例如,设置为工具栏窗口: ``` c++ setWindowFlags(Qt::Tool | Qt::WindowMinimizeButtonHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint | Qt::WindowMaximizeButtonHint | Qt::WindowStaysOnTopHint); ``` 2. 如果希望窗口合并到同一任务栏图标下,可以将 Qt::Tool 属性去掉即可。 ``` c++ setWindowFlags(Qt::Window | Qt::WindowMinimizeButtonHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint | Qt::WindowMaximizeButtonHint | Qt::WindowStaysOnTopHint); ``` 示例代码如下: ``` c++ #include <QApplication> #include <QWidget> int main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget window; window.setWindowFlags(Qt::Tool | Qt::WindowMinimizeButtonHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint | Qt::WindowMaximizeButtonHint | Qt::WindowStaysOnTopHint); window.show(); QWidget window2; window2.setWindowFlags(Qt::Tool | Qt::WindowMinimizeButtonHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint | Qt::WindowMaximizeButtonHint | Qt::WindowStaysOnTopHint); window2.show(); return app.exec(); } ``` 注意:使用 Qt::Tool 属性将窗口转换为工具栏窗口,可能会导致窗口的行为和样式与普通窗口不同。例如,工具栏窗口默认不会显示在 Windows 任务栏和 Mac OS Dock 中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值