AttributeError: module 'PyQt5.QtGui' has no attribute 'QWidget'

天大地大妈咪最大 提交于 2019-11-28 11:41:29

Your error is from here:

Ui_Widget(QtGui.QWidget)

It basically tells you what the problem is.

It seems you are mixing some QT4 and QT5 here as your import is in QT5-style, but QtGui.QWidget looks like QT4-style.

Replace the line with:

Ui_Widget(QtWidgets.QWidget)

which should be compatible according to the docs

Remark: I don't know what you are really doing, but when you mention this: Even when I change class Ui_Widget(QtGui.QWidget): to class Ui_Widget(QtGui.QtWidgets): I get AttributeError: module 'PyQt5.QtGui' has no attribute 'QtWidgets' That's correct. You already imported QtWidgets, and not from PyQt5.QtGui. Just use Ui_Widget(QtWidgets) there.

In short: all these errors seem to be related to refactoring in regards to the modules between QT4 and QT5. The docs should help.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!