<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[PySide vs PyQt ui file load.]]></title><description><![CDATA[<p dir="auto">Why does PySide ui load differ from PyQt? I'd like to use PySide since it is 'official' and has (hopefully) a more robust update cycle. Code fragments highlight the issue. Thanks, Scott</p>
<p dir="auto">PyQt6 ui or py files work and matches my development flow.<br />
PySide6 py file works, ui file fails here with:<br />
File "...\qt_test.py", line 53, in event_loop<br />
print(self.label.text())<br />
^^^^^^^^^^<br />
AttributeError: 'main' object has no attribute 'label'</p>
<p dir="auto">Minimal ui:<br />
qt_mainwindow.ui -&gt; default 'Main Window' and a label. DT Widget Designer v6.82<br />
pyuic6 qt_mainwindow.ui -o qt_mainwindow_pyqt6.py<br />
pyuic6 qt_mainwindow.ui -o qt_mainwindow_pyside6.py<br />
"""<br />
class main(PySide6.QtWidgets.QMainWindow, Ui_MainWindow):<br />
def <strong>init</strong>(self, ui_file_flag, ui_file):<br />
super(main, self).<strong>init</strong>()<br />
if ui_file_flag:<br />
print('loading ui_file file')<br />
# PyQt6.uic.loadUi(ui_file, self)<br />
# both PySide6 ui loads fail at the same place and with the same message (line-53)<br />
# PySide6.QtUiTools.loadUiType(ui_file)<br />
PySide6.QtUiTools.QUiLoader().load(ui_file)<br />
else:<br />
print('loading py file')<br />
self.setupUi(self)</p>
]]></description><link>https://forum.qt.io/topic/163532/pyside-vs-pyqt-ui-file-load.</link><generator>RSS for Node</generator><lastBuildDate>Sat, 09 May 2026 21:28:54 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/163532.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 16 Oct 2025 18:59:28 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to PySide vs PyQt ui file load. on Sat, 18 Oct 2025 07:47:08 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/swoiwode">@<bdi>swoiwode</bdi></a><br />
Yes, you have made the right changes!  Note how you changed from <code>PyQt6.uic.loadUi(ui_file, self)</code>, which loaded into <code>self</code> and gave you <code>self.label</code> etc. over to <code>self.ui = PySide6.QtUiTools.QUiLoader().load(ui_file)</code>, which returned into a newly created <code>self.ui</code> (or whatever you choose to call it) and hence gave you <code>self.ui.label</code> etc.  It's just a different way of doing things, and PySide just does not offer that parameter or loading into <code>self</code>.</p>
<p dir="auto">Looking around at what examples there are on the web I found that actually even in PyQt more people had worked from <code>self.ui = PyQt6.uic.loadUi(ui_file)</code> which is also available and similar to the PySide way than that "non-standard" <code>PyQt6.uic.loadUi(ui_file, self)</code> which the code you inherited had chosen to use.</p>
<p dir="auto">Honestly you came across one of the few difference between PyQt and PySide right from the outset in the small script you were working on.  99% of the time you should find that same code simply works from PyQt to PySide.</p>
]]></description><link>https://forum.qt.io/post/832950</link><guid isPermaLink="true">https://forum.qt.io/post/832950</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Sat, 18 Oct 2025 07:47:08 GMT</pubDate></item><item><title><![CDATA[Reply to PySide vs PyQt ui file load. on Fri, 17 Oct 2025 23:04:05 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a></p>
<pre><code>self.label
</code></pre>
<p dir="auto">comes from the .ui file.</p>
<p dir="auto">It is working now with</p>
<pre><code>self.ui = PySide6.QtUiTools.QUiLoader().load(ui_file)
</code></pre>
<p dir="auto">and using</p>
<pre><code>self.ui.label.text()
</code></pre>
<p dir="auto">will print 'TextLabel', ever second to the console.</p>
<p dir="auto">Adding</p>
<pre><code>self.ui.show()
</code></pre>
<p dir="auto">as the last line of</p>
<pre><code>__init__
</code></pre>
<p dir="auto">and removing</p>
<pre><code>window.show()
</code></pre>
<p dir="auto">in</p>
<pre><code>if __name__ == '__main__':
</code></pre>
<p dir="auto">Displays:<br />
<img src="https://ddgobkiprc33d.cloudfront.net/a9f9302e-e843-4775-909d-85087af988f5.png" alt="Screenshot 2025-10-17 160249.png" class=" img-fluid img-markdown" /><br />
I will embrace this methodology going forward.</p>
<p dir="auto">Thanks, Scott</p>
]]></description><link>https://forum.qt.io/post/832948</link><guid isPermaLink="true">https://forum.qt.io/post/832948</guid><dc:creator><![CDATA[swoiwode]]></dc:creator><pubDate>Fri, 17 Oct 2025 23:04:05 GMT</pubDate></item><item><title><![CDATA[Reply to PySide vs PyQt ui file load. on Fri, 17 Oct 2025 20:12:38 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/swoiwode">@<bdi>swoiwode</bdi></a><br />
As already said: your code has <code>self.label.text()</code>.  How or where did <code>self.label</code> ever get created?  Certainly it is not by <code>PySide6.QtUiTools.QUiLoader().load(ui_file)</code>.  So was it (somehow) created before by <code>PyQt6.uic.loadUi(ui_file, self)</code>?  We don't know, it's a third party product.  No, they are not the same.  At some level they both load a <code>.ui</code> file, but what they then do is different and unknown for <code>PyQt6.uic.loadUi()</code>.</p>
<p dir="auto">I suggested you examine its documentation and code if you want to understand what you would need to do from PySide.  Just directly replacing one call with the other clearly does not work, as you have discovered.</p>
<p dir="auto">P.S.<br />
Read <a href="https://www.pythonguis.com/faq/pyqt5-vs-pyside2/" target="_blank" rel="noopener noreferrer nofollow ugc">https://www.pythonguis.com/faq/pyqt5-vs-pyside2/</a> , <strong>UI files</strong> section.  It's for PyQt5 vs PySide2, but it will be same for PyQt6 vs PySide6.  It mentions "but you can work around this with a separate function" and gives some code.  But I'm still not sure who that to relates to your existing usage of <code>self.label</code>.</p>
<p dir="auto">See also <a href="https://www.pythontutorial.net/pyqt/qt-designer/#using-ui-file-directly" target="_blank" rel="noopener noreferrer nofollow ugc">https://www.pythontutorial.net/pyqt/qt-designer/#using-ui-file-directly</a>.  And <a href="https://python-forum.io/thread-35619.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://python-forum.io/thread-35619.html</a>.</p>
<p dir="auto">I don't know where <code>PyQt6.uic</code> is documented?  [Good luck tracking it down: the only instance in The Universe turns out to be <a href="https://riverbankcomputing.com/static/Docs/PyQt6/api/uic/uic-module.html#loadUi" target="_blank" rel="noopener noreferrer nofollow ugc">https://riverbankcomputing.com/static/Docs/PyQt6/api/uic/uic-module.html#loadUi</a> and goodness knows how you get there.]</p>
<p dir="auto">If by any chance that <code>uic</code> in its name indicates that it requires the PyQt6 equivalent of <code>uic</code> to be <em>shipped and found at runtime</em>, and that is run to generated Python code at runtime which is somehow imported and hence you can get a variable like <code>label</code> created at runtime, then I don't think PySide has an equivalent and you would have to change some of your code.  [The preceding may not be the case at all, I am not sure where I might have seen that it might work like that.]</p>
<p dir="auto">Hmm, I think that <a href="https://python-forum.io/thread-35619.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://python-forum.io/thread-35619.html</a> may be key and the only docs I have seen so far.  Someone says</p>
<blockquote>
<p dir="auto">Is there any way to load ui with Pyside6 that the widgets become attributes of the class instead of attributes of another attribute of the class e.g. "self.ui"</p>
</blockquote>
<p dir="auto">So that does imply that <code>PySide6.QtUiTools.QUiLoader().load(ui_file)</code> creates Python "attributes/variables" at runtime for named widgets in the <code>.ui</code> file (I still don't know where this behaviour is documented) and so does <code>PyQt6.uic.loadUi()</code>.  The difference is that in PyQt you can put that directly into <code>self</code> via <code>PyQt6.uic.loadUi(ui_file, self)</code> whereas from <code>PySide6.QtUiTools.QUiLoader().load(ui_file)</code> you get back a "dummy" class you must use, like <code>self.ui = PySide6.QtUiTools.QUiLoader().load(ui_file)</code> and then you can access <code>self.ui.label</code>.  I think you will need to change your code to work off <code>self.ui</code> where appropriate.</p>
<p dir="auto">FWIW, loading a <code>.ui</code> file into <code>self.ui</code> is the direct equivalent of the way it is done in <code>this-&gt;ui</code> from C++.  In that sense the PySide interface follows this pattern while <code>PyQt6.uic.loadUi(ui_file, self)</code> is "non-standard".</p>
]]></description><link>https://forum.qt.io/post/832940</link><guid isPermaLink="true">https://forum.qt.io/post/832940</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Fri, 17 Oct 2025 20:12:38 GMT</pubDate></item><item><title><![CDATA[Reply to PySide vs PyQt ui file load. on Fri, 17 Oct 2025 18:20:57 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a><br />
Sample error message, python code and ui file, as requested.</p>
<p dir="auto">**** error message start ****</p>
<pre><code>C:\Users\Scott\Desktop\PythonDev\qt\.venv\Scripts\python.exe C:\Users\Scott\Desktop\PythonDev\qt\qt_test.py -iuf .\qt_mainwindow.ui 
Traceback (most recent call last):
  File "C:\Users\Scott\Desktop\PythonDev\qt\qt_test.py", line 70, in &lt;module&gt;
    window: PySide6.QtWidgets.QMainWindow = main(m_ui_file_flag, m_ui_file)
                                            ~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Scott\Desktop\PythonDev\qt\qt_test.py", line 44, in __init__
    self.event_loop()
    ~~~~~~~~~~~~~~~^^
  File "C:\Users\Scott\Desktop\PythonDev\qt\qt_test.py", line 57, in event_loop
    print(self.label.text())
          ^^^^^^^^^^
AttributeError: 'main' object has no attribute 'label'
</code></pre>
<p dir="auto">**** error message end ****</p>
<p dir="auto">**** python code start ****</p>
<pre><code>"""
barebone implementations to load ui file for Pyside or PyQt, enable one or the other
qt_mainwindow.ui -&gt; default 'Main Window' and a label. DT Widget Designer v6.82

This code should print 'TextLabel' to the console every second
"""
import sys

# ---- PyQt ---- comment/uncomment as needed
# import PyQt6.QtWidgets
# import PyQt6.uic
# import PyQt6.QtGui
# import PyQt6.QtCore

# ---- PySide ---- comment/uncomment as needed
import PySide6.QtWidgets
import PySide6.QtUiTools
import PySide6.QtGui
import PySide6.QtCore

# ---- PyQt ---- comment/uncomment as needed
# from qt_mainwindow_pyqt6 import Ui_MainWindow

# ---- PySide ---- comment/uncomment as needed
from qt_mainwindow_pyside6 import Ui_MainWindow


# ---- PyQt ---- comment/uncomment as needed
# class main(PyQt6.QtWidgets.QMainWindow, Ui_MainWindow):

# ---- PySide ---- comment/uncomment as needed
class main(PySide6.QtWidgets.QMainWindow, Ui_MainWindow):
    def __init__(self, ui_file_flag, ui_file):
        super(main, self).__init__()
        if ui_file_flag:
            # ---- PyQt ---- comment/uncomment as needed
            # PyQt6.uic.loadUi(ui_file, self)

            # ---- PySide ---- comment/uncomment as needed
            PySide6.QtUiTools.QUiLoader().load(ui_file)
        else:
            self.setupUi(self)

        self.event_loop()

        # ---- PyQt ---- comment/uncomment as needed
        # self.timer = PyQt6.QtCore.QTimer()

        # ---- PySide ---- comment/uncomment as needed
        self.timer = PySide6.QtCore.QTimer()

        self.timer.timeout.connect(self.event_loop)  # noqa
        self.timer.start(1000)

    # FAIL, PySide ui fiie for AttributeError: 'main' object has no attribute 'label'
    def event_loop(self) -&gt; None:
        print(self.label.text())


if __name__ == '__main__':
    m_ui_file_flag: bool = True  # &lt;- developer switch, False for release.
    m_ui_file = r'.\qt_mainwindow.ui'

    # ---- PyQt ---- comment/uncomment as needed
    # app = PyQt6.QtWidgets.QApplication(sys.argv)
    # window: PyQt6.QtWidgets.QMainWindow = main(m_ui_file_flag, m_ui_file)

    # ---- PySide ---- comment/uncomment as needed
    app = PySide6.QtWidgets.QApplication(sys.argv)
    window: PySide6.QtWidgets.QMainWindow = main(m_ui_file_flag, m_ui_file)

    window.show()
    sys.exit(app.exec())
</code></pre>
<p dir="auto">**** python code end ****</p>
<p dir="auto">**** ui code start ****</p>
<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;ui version="4.0"&gt;
 &lt;class&gt;MainWindow&lt;/class&gt;
 &lt;widget class="QMainWindow" name="MainWindow"&gt;
  &lt;property name="geometry"&gt;
   &lt;rect&gt;
    &lt;x&gt;0&lt;/x&gt;
    &lt;y&gt;0&lt;/y&gt;
    &lt;width&gt;800&lt;/width&gt;
    &lt;height&gt;600&lt;/height&gt;
   &lt;/rect&gt;
  &lt;/property&gt;
  &lt;property name="windowTitle"&gt;
   &lt;string&gt;MainWindow&lt;/string&gt;
  &lt;/property&gt;
  &lt;widget class="QWidget" name="centralwidget"&gt;
   &lt;widget class="QLabel" name="label"&gt;
    &lt;property name="geometry"&gt;
     &lt;rect&gt;
      &lt;x&gt;370&lt;/x&gt;
      &lt;y&gt;250&lt;/y&gt;
      &lt;width&gt;49&lt;/width&gt;
      &lt;height&gt;16&lt;/height&gt;
     &lt;/rect&gt;
    &lt;/property&gt;
    &lt;property name="text"&gt;
     &lt;string&gt;TextLabel&lt;/string&gt;
    &lt;/property&gt;
   &lt;/widget&gt;
  &lt;/widget&gt;
  &lt;widget class="QMenuBar" name="menubar"&gt;
   &lt;property name="geometry"&gt;
    &lt;rect&gt;
     &lt;x&gt;0&lt;/x&gt;
     &lt;y&gt;0&lt;/y&gt;
     &lt;width&gt;800&lt;/width&gt;
     &lt;height&gt;33&lt;/height&gt;
    &lt;/rect&gt;
   &lt;/property&gt;
  &lt;/widget&gt;
  &lt;widget class="QStatusBar" name="statusbar"/&gt;
 &lt;/widget&gt;
 &lt;resources/&gt;
 &lt;connections/&gt;
&lt;/ui&gt;
</code></pre>
<p dir="auto">**** ui code end ****</p>
]]></description><link>https://forum.qt.io/post/832939</link><guid isPermaLink="true">https://forum.qt.io/post/832939</guid><dc:creator><![CDATA[swoiwode]]></dc:creator><pubDate>Fri, 17 Oct 2025 18:20:57 GMT</pubDate></item><item><title><![CDATA[Reply to PySide vs PyQt ui file load. on Fri, 17 Oct 2025 15:54:24 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a>,<br />
Thanks for the replies. I will upload the complete code, ui file and format too.</p>
<p dir="auto">I was afraid that ui loading was one of the differences between PySide and PyQt, prior searches gave me that belief.</p>
<p dir="auto">BTW - Any non-functional print statements are my breadcrumbs :p. The development flow starts with a uniquely named ui file and template.  Converted to py, so the ‘wiring’ can be confirmed. Then further GUI development is done with live user engagement/presence, rapid visuals of the GUI are needed and changes made as required. Converting ui to py, adjusting code as needed, passing through pyinstaller and checking functionality are done afterwards. I can deliver a solution within ~hour.</p>
<p dir="auto">Thanks, Scott</p>
]]></description><link>https://forum.qt.io/post/832937</link><guid isPermaLink="true">https://forum.qt.io/post/832937</guid><dc:creator><![CDATA[swoiwode]]></dc:creator><pubDate>Fri, 17 Oct 2025 15:54:24 GMT</pubDate></item><item><title><![CDATA[Reply to PySide vs PyQt ui file load. on Fri, 17 Oct 2025 10:11:24 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a> , <a class="plugin-mentions-user plugin-mentions-a" href="/user/swoiwode">@<bdi>swoiwode</bdi></a><br />
<code>PySide6.QtUiTools.QUiLoader().load(ui_file)</code> is the function to use.  I presume the OP's issue is that he has <em>existing</em> code using <code>PyQt6.uic.loadUi(ui_file, self)</code>, which loads into <code>self</code> while the PySide call instead returns some newly created widget?  PySide and PyQt are <em>mostly</em> similar/identical, but I do not they do their dynamic loading of a <code>.ui</code> file differently.  I don't know whether you can achieve same from PySide.</p>
<p dir="auto">Further, I only <em>expected</em> these dynamic loadings to produce a widget tree you can access via <code>findChild&lt;&gt;()</code>.  But the existing code is apparently failing on some existing <code>self.label.text()</code> call.  <code>self.label</code> must be a Python variable/reference <code>label</code> set to some <code>QLabel</code> found in the <code>.ui</code> file.  I do not know how that gets set in the first place.  Is it done explicitly somewhere in OP's code?  Did I read that either or both of the respective PySide and PyQt calls actually do some <code>uic</code> running magic at <em>runtime</em> to (perhaps?) produce Python code with variables for the widgets in the <code>.ui</code> file?  I think the OP needs to examine the documentation or code of the respective PySide/PyQt methods.</p>
]]></description><link>https://forum.qt.io/post/832924</link><guid isPermaLink="true">https://forum.qt.io/post/832924</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Fri, 17 Oct 2025 10:11:24 GMT</pubDate></item><item><title><![CDATA[Reply to PySide vs PyQt ui file load. on Fri, 17 Oct 2025 05:09:15 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/swoiwode">@<bdi>swoiwode</bdi></a> Where is this print statement in your code?<br />
You do not store what load(ui_file) returns anywhere - how are you going to use it?<br />
<a href="https://doc.qt.io/qtforpython-6/tutorials/basictutorial/uifiles.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qtforpython-6/tutorials/basictutorial/uifiles.html</a></p>
<p dir="auto">Please format you code properly when posting.</p>
]]></description><link>https://forum.qt.io/post/832903</link><guid isPermaLink="true">https://forum.qt.io/post/832903</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Fri, 17 Oct 2025 05:09:15 GMT</pubDate></item></channel></rss>