Qt QGridLayout bug

本文讨论了如何使用Qt的QDialog和QWidget实现非模态窗口置顶功能,以及在使用QGridLayout时遇到的间隔显示不均的问题,可能与Qt的底层内核有关,提出了这可能是一个bug。建议如果不介意,可以继续使用QGridLayout,否则可以考虑使用QTableWidget作为替代方案。
摘要由CSDN通过智能技术生成

如果需要让一个窗口支持模态和非模态窗口,一般是需要将改窗口设置为QDailog,

实现该功能的一个关键点是设置了setStyleSheet(Qt::Window),源码如下:

        Widget = 0x00000000,

        Window = 0x00000001,

        Dialog = 0x00000002 | Window,

 

Qt::Dialog

0x00000002 | Window

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.

 

 

确实可以使用QDialog实现模态和非模态对话框的功能,还有其他方法实现类似的功能吗,可以使用QWidget实现类似的效果吗,可以使用QWidget实现窗口置顶且为非模态对话框的功能,如果需求不要求是模态对话框,只需要窗口置顶和非模态窗口,可以使用QDialog实现类似的功能,也可以使用QWidget实现,QWidget本身默认是没有这样的功能的需要多做一些设置就可以实现了,可以设置QWidget::setWindowsFlags(this->windowsFlags() | Qt::Window),就可以有这样的功能。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值