原本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)
690

被折叠的 条评论
为什么被折叠?



