Reputation: 49
I am just learning how to create GUI using Qtdesigner and Pycharm. so I build a really simple GUI with tow bottoms an a label. after compiling the .ui file in pycharm and writing this code to execute it:
from PySide2 import QtWidgets
from Algo_UI import untitled
class QtApp ( untitled.Ui_MainWindow, QtWidgets.QMainWindow):
def __init__(self):
super(QtApp, self).__init__()
self.setupUi(self)
if __name__ == '__main__':
app = QtWidgets.QApplication()
qt_app = QtApp()
qt_app.show()
app.exec_()
I got this Error:
Traceback (most recent call last):
File "/home/al/0-Projects/Python/Algo/AlgoApp/Main.py", line 11, in <module>
qt_app = QtApp()
File "/home/al/0-Projects/Python/Algo/AlgoApp/Main.py", line 7, in __init__
self.setupUi(self)
File "/home/al/0-Projects/Python/Algo/AlgoApp/Algo_UI/untitled.py", line 17, in setupUi
self.centralwidget = QtWidgets.QWidget(MainWindow)
TypeError: QWidget(parent: QWidget = None, flags: Union[Qt.WindowFlags, Qt.WindowType] =
Qt.WindowFlags()): argument 1 has unexpected type 'QtApp'
here is the first part of the Untitled.py file, where line-17 on the error massage refers to.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
self.centralwidget = QtWidgets.QWidget(MainWindow)
how could I solve this Problem ?
Upvotes: 1
Views: 1418
Reputation: 243897
The error is caused because you should not combine PyQt5 with PySide2 as they can cause hard to debug errors. Although both classes use Qt they create different wrappers so a PyQt5 object cannot be used by a PySide2 object and vice versa. The solution is just to use a library, in this case change from PySide2 import QtWidgets
to from PyQt5 import QtWidgets
. Also change app = QtWidgets.QApplication()
to app = QtWidgets.QApplication([])
.
Upvotes: 2