(已解决)PyQt6 设置无边框网页出现AttributeError: type object ‘Qt‘ has no attribute ‘FramelessWindowHint‘

原本PyQt5设置无边框的代码如下

self.setWindowFlag(QtCore.Qt.FramelessWindowHint)
self.setAttribute(QtCore.Qt.WA_TranslucentBackground)

但在PyQt6使用会出现报错AttributeError: type object 'Qt' has no attribute 'FramelessWindowHint'

这个错误是因为使用的 QtCore.Qt 并没有 FramelessWindowHint 这个属性。实际上,在 PyQt6 中,很多原本在 QtCore.Qt 中的常量被拆分或重命名了。
应该改用 QtCore.Qt.WindowType.FramelessWindowHint 来代替。

修改后的代码如下

self.setWindowFlag(QtCore.Qt.WindowType.FramelessWindowHint)
self.setAttribute(QtCore.Qt.WidgetAttribute.WA_TranslucentBackground)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值