Some .ui files/elements not loading in Python
-
I have 2 almost identical .ui files, but one of them isn't loading. I can't tell a significant difference in the files, but one will load the actual screen designed in Qt Designer, but one will just output an error (I need it to load the one that doesn't currently work). Here is the main code, and the errors that I get when I try to load the non-functioning file. I want to load this file as the layout and formatting is nicer than the other.
import sys from PyQt5.uic import loadUi from PyQt5 import * from PyQt5.QtWidgets import * class WelcomeScreen(QDialog): def __init__(self): super(WelcomeScreen, self).__init__() loadUi('test.ui', self) self.show() # main code block app = QApplication(sys.argv) welcome = WelcomeScreen() widget = QStackedWidget() widget.addWidget(welcome) widget.setFixedSize(480, 640) widget.show() try: sys.exit(app.exec_()) except (): print('Exiting')
and here is the error message I get when loading the .ui file
Traceback (most recent call last): File "C:\Users\socks\Desktop\realLogin\pythonProject\main.py", line 16, in <module> welcome = WelcomeScreen() ^^^^^^^^^^^^^^^ File "C:\Users\socks\Desktop\realLogin\pythonProject\main.py", line 10, in __init__ loadUi('test.ui', self) File "C:\Users\socks\Desktop\realLogin\pythonProject\.venv\Lib\site-packages\PyQt5\uic\__init__.py", line 241, in loadUi return DynamicUILoader(package).loadUi(uifile, baseinstance, resource_suffix) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\socks\Desktop\realLogin\pythonProject\.venv\Lib\site-packages\PyQt5\uic\Loader\loader.py", line 66, in loadUi return self.parse(filename, resource_suffix) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\socks\Desktop\realLogin\pythonProject\.venv\Lib\site-packages\PyQt5\uic\uiparser.py", line 1037, in parse actor(elem) File "C:\Users\socks\Desktop\realLogin\pythonProject\.venv\Lib\site-packages\PyQt5\uic\uiparser.py", line 828, in createUserInterface self.traverseWidgetTree(elem) File "C:\Users\socks\Desktop\realLogin\pythonProject\.venv\Lib\site-packages\PyQt5\uic\uiparser.py", line 806, in traverseWidgetTree handler(self, child) File "C:\Users\socks\Desktop\realLogin\pythonProject\.venv\Lib\site-packages\PyQt5\uic\uiparser.py", line 273, in createWidget self.traverseWidgetTree(elem) File "C:\Users\socks\Desktop\realLogin\pythonProject\.venv\Lib\site-packages\PyQt5\uic\uiparser.py", line 806, in traverseWidgetTree handler(self, child) File "C:\Users\socks\Desktop\realLogin\pythonProject\.venv\Lib\site-packages\PyQt5\uic\uiparser.py", line 273, in createWidget self.traverseWidgetTree(elem) File "C:\Users\socks\Desktop\realLogin\pythonProject\.venv\Lib\site-packages\PyQt5\uic\uiparser.py", line 806, in traverseWidgetTree handler(self, child) File "C:\Users\socks\Desktop\realLogin\pythonProject\.venv\Lib\site-packages\PyQt5\uic\uiparser.py", line 503, in createLayout self.traverseWidgetTree(elem) File "C:\Users\socks\Desktop\realLogin\pythonProject\.venv\Lib\site-packages\PyQt5\uic\uiparser.py", line 806, in traverseWidgetTree handler(self, child) File "C:\Users\socks\Desktop\realLogin\pythonProject\.venv\Lib\site-packages\PyQt5\uic\uiparser.py", line 546, in handleItem self.traverseWidgetTree(elem) File "C:\Users\socks\Desktop\realLogin\pythonProject\.venv\Lib\site-packages\PyQt5\uic\uiparser.py", line 806, in traverseWidgetTree handler(self, child) File "C:\Users\socks\Desktop\realLogin\pythonProject\.venv\Lib\site-packages\PyQt5\uic\uiparser.py", line 264, in createWidget self.stack.push(self.setupObject(widget_class, parent, elem)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\socks\Desktop\realLogin\pythonProject\.venv\Lib\site-packages\PyQt5\uic\uiparser.py", line 230, in setupObject self.wprops.setProperties(obj, branch) File "C:\Users\socks\Desktop\realLogin\pythonProject\.venv\Lib\site-packages\PyQt5\uic\properties.py", line 417, in setProperties getattr(widget, 'set%s%s' % (ascii_upper(prop_name[0]), prop_name[1:]))(prop_value) TypeError: setWhatsThis(self, a0: Optional[str]): argument 1 has unexpected type 'int' Process finished with exit code 1
Another recurring issue is not being able to use text alignment, giving me errors like :
AttributeError: type object 'Qt' has no attribute 'Qt::AlignmentFlag::AlignCenter'
-
@anthnyshark said in Some .ui files/elements not loading in Python:
I have 2 almost identical .ui files, but one of them isn't loading. I can't tell a significant difference in the files
Use a "differencer" tool to compare their content.
AttributeError: type object 'Qt' has no attribute 'Qt::AlignmentFlag::AlignCenter'
This is to do with PyQt5/6. At 5 it may have been
Qt::AlignCenter
. Are you using a very recent version of Designer/Creator? I think the .ui
files it generates may not be backwardly compatible to PyQt5 now. If that is so might be the cause of your problems/different file behaviour.