<?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[Loading multiple .ui files]]></title><description><![CDATA[<p dir="auto">I want the user to be able to click on a certain button to open a new window from a different .ui file to the main window, but my current code to do so doesn't do anything. My main window loads perfectly and the button input is correctly detected, it just seems that only the first .ui file my code loads actually opens. Here is my python code:</p>
<pre><code>import sys
import os
from PySide6 import QtCore, QtWidgets, QtGui
from PySide6.QtUiTools import QUiLoader
from PySide6.QtCore import QFile
import screeninfo

uiPath = os.path.dirname(os.path.abspath(__file__)) + "/ui/"
# All ui files are stored in this path

monitor = screeninfo.get_monitors()[0]
x = monitor.width
y = monitor.height
uiLoader = QUiLoader()
mainWindow = QFile(uiPath + "mainwindow.ui")
perlin = QFile(uiPath + "perlinnoise.ui")
# Fetch things necessary for UI loading

def menuTriggers(button):
    print("you presse d button!!", button.objectName())
    if button.objectName() == "actionPerlin_Noise":
        perlinWindow = uiLoader.load(perlin)
        perlinWindow.show()
        print("it must be visible noww") # this does print so my the button is definitely detected

if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    window = uiLoader.load(mainWindow)
    window.show()
    window.menubar.triggered.connect(menuTriggers)
    sys.exit(app.exec())

</code></pre>
]]></description><link>https://forum.qt.io/topic/164912/loading-multiple-.ui-files</link><generator>RSS for Node</generator><lastBuildDate>Thu, 10 Sep 2026 12:08:36 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/164912.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 21 Jul 2026 13:03:49 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Loading multiple .ui files on Tue, 21 Jul 2026 14:19:13 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/samuraidestroy">@<bdi>SamuraiDestroy</bdi></a> said in <a href="/post/839284">Loading multiple .ui files</a>:</p>
<blockquote>
<p dir="auto">perlinWindow = uiLoader.load(perlin)</p>
</blockquote>
<p dir="auto"><code>perlInWindow</code> is a Python local variable to the <code>menuTriggers()</code> function.  As soon as that exits --- after the <code>show()</code> and the <code>print()</code> --- it is released/destroyed and your window goes with it.  You wont even see it flash up and disappear.  In Python you have to be careful about <em>scope/lifetime</em> of variable references to objects, and make them persist.</p>
<p dir="auto">From where you are now you could probably make <code>perlInWindow</code> be Python <code>global</code>.  If you were inside a class you would probably store it in <code>self</code>, but you are not working with your own classes.</p>
<p dir="auto">On a side note: as per another newcomer's question in another topic, I think you should re-examine your use of <code>.ui</code> file dynamic loading.  Before you get into the habit of using it you would be much better off changing over to the <code>uic</code> method.  See <a class="plugin-mentions-user plugin-mentions-a" href="/user/friedemannkleint">@<bdi>friedemannkleint</bdi></a> reply to a related situation at <a href="https://forum.qt.io/post/839262">https://forum.qt.io/post/839262</a> and my reply.  You/nearly everybody should be using <a href="https://doc.qt.io/qtforpython-6/tutorials/basictutorial/uifiles.html#option-a-generating-a-python-class" target="_blank" rel="noopener noreferrer nofollow ugc">Option A: Generating a Python class</a> where you are currently using <a href="https://doc.qt.io/qtforpython-6/tutorials/basictutorial/uifiles.html#option-b-loading-it-directly" target="_blank" rel="noopener noreferrer nofollow ugc">Option B: Loading it directly</a>.</p>
]]></description><link>https://forum.qt.io/post/839288</link><guid isPermaLink="true">https://forum.qt.io/post/839288</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Tue, 21 Jul 2026 14:19:13 GMT</pubDate></item><item><title><![CDATA[Reply to Loading multiple .ui files on Wed, 22 Jul 2026 10:53:17 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> said in <a href="/post/839288">Loading multiple .ui files</a>:</p>
<blockquote>
<p dir="auto">On a side note: as per another newcomer's question in another topic, I think you should re-examine your use of .ui file dynamic loading. Before you get into the habit of using it you would be much better off changing over to the uic method. See <a class="plugin-mentions-user plugin-mentions-a" href="/user/friedemannkleint">@<bdi>friedemannkleint</bdi></a> reply to a related situation at <a href="https://forum.qt.io/post/839262">https://forum.qt.io/post/839262</a> and my reply. You/nearly everybody should be using Option A: Generating a Python class where you are currently using Option B: Loading it directly.</p>
</blockquote>
<p dir="auto">What exactly makes Option A better than Option B?</p>
]]></description><link>https://forum.qt.io/post/839311</link><guid isPermaLink="true">https://forum.qt.io/post/839311</guid><dc:creator><![CDATA[SamuraiDestroy]]></dc:creator><pubDate>Wed, 22 Jul 2026 10:53:17 GMT</pubDate></item><item><title><![CDATA[Reply to Loading multiple .ui files on Tue, 21 Jul 2026 14:19:13 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/samuraidestroy">@<bdi>SamuraiDestroy</bdi></a> said in <a href="/post/839284">Loading multiple .ui files</a>:</p>
<blockquote>
<p dir="auto">perlinWindow = uiLoader.load(perlin)</p>
</blockquote>
<p dir="auto"><code>perlInWindow</code> is a Python local variable to the <code>menuTriggers()</code> function.  As soon as that exits --- after the <code>show()</code> and the <code>print()</code> --- it is released/destroyed and your window goes with it.  You wont even see it flash up and disappear.  In Python you have to be careful about <em>scope/lifetime</em> of variable references to objects, and make them persist.</p>
<p dir="auto">From where you are now you could probably make <code>perlInWindow</code> be Python <code>global</code>.  If you were inside a class you would probably store it in <code>self</code>, but you are not working with your own classes.</p>
<p dir="auto">On a side note: as per another newcomer's question in another topic, I think you should re-examine your use of <code>.ui</code> file dynamic loading.  Before you get into the habit of using it you would be much better off changing over to the <code>uic</code> method.  See <a class="plugin-mentions-user plugin-mentions-a" href="/user/friedemannkleint">@<bdi>friedemannkleint</bdi></a> reply to a related situation at <a href="https://forum.qt.io/post/839262">https://forum.qt.io/post/839262</a> and my reply.  You/nearly everybody should be using <a href="https://doc.qt.io/qtforpython-6/tutorials/basictutorial/uifiles.html#option-a-generating-a-python-class" target="_blank" rel="noopener noreferrer nofollow ugc">Option A: Generating a Python class</a> where you are currently using <a href="https://doc.qt.io/qtforpython-6/tutorials/basictutorial/uifiles.html#option-b-loading-it-directly" target="_blank" rel="noopener noreferrer nofollow ugc">Option B: Loading it directly</a>.</p>
]]></description><link>https://forum.qt.io/post/839288</link><guid isPermaLink="true">https://forum.qt.io/post/839288</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Tue, 21 Jul 2026 14:19:13 GMT</pubDate></item></channel></rss>