PyQt5, PySide6 and PyCharm issue
-
I am starting using PySide6. I am using the software in title. I get the following error:
I developed the UI with Qt 5 designer and then converted it to a .py file.
Traceback (most recent call last): File "/media/soporte/DD Externo/LMario/ITSTA/Carga Académica/AY-Feb-Jul25/Programación Visual/Prácticas Python PySide/HolaMundoEnv/HolaMundo.py", line 23, in <module> form = HolaMundo() File "/media/soporte/DD Externo/LMario/ITSTA/Carga Académica/AY-Feb-Jul25/Programación Visual/Prácticas Python PySide/HolaMundoEnv/HolaMundo.py", line 15, in __init__ self.setupUi(self) File "/media/soporte/DD Externo/LMario/ITSTA/Carga Académica/AY-Feb-Jul25/Programación Visual/Prácticas Python PySide/HolaMundoEnv/HolaMundoGUI.py", line 18, in setupUi self.centralwidget = QtWidgets.QWidget(MainWindow) TypeError: QWidget(parent: Optional[QWidget] = None, flags: Union[Qt.WindowFlags, Qt.WindowType] = Qt.WindowFlags()): argument 1 has unexpected type 'HolaMundo' Process finished with exit code 1
The scripts are:
import os import sys if sys.platform == "linux": # Fixes "undefined symbol: wl_proxy_marshal_flags": https://bugreports.qt.io/browse/QTBUG-114635}} os.environ.setdefault("QT_QPA_PLATFORM", "xcb") from PySide6 import QtWidgets as qtw from HolaMundoGUI import Ui_MainWindow class HolaMundo(qtw.QWidget, Ui_MainWindow): def __init__(self): super().__init__() self.setupUi(self) self.show() if __name__ == "__main__": app = qtw.QApplication(sys.argv) form = HolaMundo() sys.exit(app.exec())
HolaMundoGUI is
# -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'HolaMundoGUI.ui' # # Created by: PyQt5 UI code generator 5.15.9 # # WARNING: Any manual changes made to this file will be lost when pyuic5 is # run again. Do not edit this file unless you know what you are doing. 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) self.centralwidget.setObjectName("centralwidget") self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.centralwidget) self.horizontalLayout_2.setObjectName("horizontalLayout_2") self.horizontalLayout = QtWidgets.QHBoxLayout() self.horizontalLayout.setObjectName("horizontalLayout") self.pushButton = QtWidgets.QPushButton(self.centralwidget) self.pushButton.setMaximumSize(QtCore.QSize(100, 30)) self.pushButton.setObjectName("pushButton") self.horizontalLayout.addWidget(self.pushButton) self.horizontalLayout_2.addLayout(self.horizontalLayout) MainWindow.setCentralWidget(self.centralwidget) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) self.pushButton.setText(_translate("MainWindow", "Aceptar"))
-
Hi and welcome to devnet,
You HolaMundo a QWidget however from your Ui_MainWindow it's clearly a QMainWindow. You cannot just change the base class like that.
-
Thanks for your help, but I need more guidance.
Do I need to regenerate HolaMUndoGUI.py in another way or is the problem solved by making changes to the main program?
Thanks.
-
The less error prone would be to revert that file back to it's original name and content.
There's a logic why the UI file and then the generated class share the same name. -
@LMario
I don't know quite what @SGaist is getting at about different names/content. However above all your first file hasfrom PySide6 import QtWidgets as qtw
while your second file has
from PyQt5 import QtCore, QtGui, QtWidgets
What is going on here? Per your title you certainly cannot mix either PyQt and PySide nor anything Qt5 with Qt6.