Note that there are some explanatory texts on larger screens.

plurals
  1. POPyQt: Button in .UI doesn't show when run
    primarykey
    data
    text
    <p><strong>SOLVED</strong><br> I changed: </p> <blockquote> <p>self.ui = base_class() </p> </blockquote> <p>Into: </p> <blockquote> <p>self.ui = form_class()<br> self.ui.setupUi(self) </p> </blockquote> <p>And now it works!</p> <hr> <p>I'm trying to get some code working so I can use the .ui file on the fly. This way updates with Qt Designer are immediately used when I run the python code.</p> <p>After fiddling and using snippets I ended up with the following code. But somehow the button in the .ui doesn't show. Anyone an idea?</p> <pre><code>import sys,os from PyQt4 import QtCore, QtGui, uic form_class, base_class = uic.loadUiType('try_ui.ui') class MainWindow(QtGui.QMainWindow): def __init__(self, parent = None): QtGui.QWidget.__init__(self, parent) self.ui = base_class() if __name__ == "__main__": app = QtGui.QApplication(sys.argv) myapp = MainWindow() myapp.show() sys.exit(app.exec_()) </code></pre> <p>And try_ui.ui a simple button:</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;323&lt;/width&gt; &lt;height&gt;111&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="QPushButton" name="pushButton"&gt; &lt;property name="geometry"&gt; &lt;rect&gt; &lt;x&gt;120&lt;/x&gt; &lt;y&gt;30&lt;/y&gt; &lt;width&gt;75&lt;/width&gt; &lt;height&gt;23&lt;/height&gt; &lt;/rect&gt; &lt;/property&gt; &lt;property name="text"&gt; &lt;string&gt;PushButton&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;323&lt;/width&gt; &lt;height&gt;21&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>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload