Issue
I am trying to display a simple GUI
# Form implementation generated from reading ui file 'UI/form.ui'
# Created by: PyQt6 UI code generator 6.1.0
# WARNING: Any manual changes made to this file will be lost when pyuic6
# is run again. Do not edit this file unless you know what you are doing.
from PyQt6 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(886, 487)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
self.gridLayout.setObjectName("gridLayout")
self.Enter = QtWidgets.QPushButton(self.centralwidget)
self.Enter.setObjectName("Enter")
self.gridLayout.addWidget(self.Enter, 2, 0, 1, 1)
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setLayoutDirection(QtCore.Qt.LayoutDirection.RightToLeft)
self.label.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
self.label.setObjectName("label")
self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
self.plainTextEdit = QtWidgets.QPlainTextEdit(self.centralwidget)
self.plainTextEdit.setObjectName("plainTextEdit")
self.gridLayout.addWidget(self.plainTextEdit, 1, 0, 1, 1)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 886, 20))
self.menubar.setObjectName("menubar")
self.menuFile = QtWidgets.QMenu(self.menubar)
self.menuFile.setObjectName("menuFile")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.actionUpload = QtGui.QAction(MainWindow)
self.actionUpload.setShortcutContext(QtCore.Qt.WindowShortcut)
self.actionUpload.setMenuRole(QtGui.QAction.AboutQtRole)
self.actionUpload.setObjectName("actionUpload")
self.menuFile.addAction(self.actionUpload)
self.menubar.addAction(self.menuFile.menuAction())
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.Enter.setText(_translate("MainWindow", "Enter"))
self.label.setText(_translate("MainWindow", "Enter Text Below Or Upload File"))
self.menuFile.setTitle(_translate("MainWindow", "File"))
self.actionUpload.setText(_translate("MainWindow", "Upload"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec())
but I get Exception has occurred: TypeError I have tried using pyuic6 again and to no avail
I am using PyQt6 and am running a Debian Linux based OS
Solution
If this code is generated by pyuic then it is a PyQt bug. In PyQt6 the flags and enumerations are stricter so you must change
self.actionUpload.setShortcutContext(QtCore.Qt.WindowShortcut)
self.actionUpload.setMenuRole(QtGui.QAction.AboutQtRole)
to:
self.actionUpload.setShortcutContext(QtCore.Qt.ShortcutContext.WindowShortcut)
self.actionUpload.setMenuRole(QtGui.QAction.MenuRole.AboutQtRole)
Answered By - eyllanesc
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.