close

[Solved] AttributeError: module ‘PyQt5.QtGui’ has no attribute ‘QWidget’

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error AttributeError: module ‘PyQt5.QtGui’ has no attribute ‘QWidget’ in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How AttributeError: module ‘PyQt5.QtGui’ has no attribute ‘QWidget’ Error Occurs?

Today I get the following error AttributeError: module ‘PyQt5.QtGui’ has no attribute ‘QWidget’ in python.

How To Solve AttributeError: module ‘PyQt5.QtGui’ has no attribute ‘QWidget’ Error ?

  1. How To Solve AttributeError: module 'PyQt5.QtGui' has no attribute 'QWidget' Error ?

    To Solve AttributeError: module 'PyQt5.QtGui' has no attribute 'QWidget' Error It seems you are mixing some QT4 and QT5 here as your import is in QT5-style, but QtGui.QWidget looks like QT4-style.

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

    To Solve AttributeError: module 'PyQt5.QtGui' has no attribute 'QWidget' Error It seems you are mixing some QT4 and QT5 here as your import is in QT5-style, but QtGui.QWidget looks like QT4-style.

Solution 1

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.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read