Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>And for the people who like PySide.</p> <pre><code>import sys,os from PySide import QtCore, QtGui, QtUiTools class MainWindow(QtGui.QMainWindow): MESSAGE = "Hello!" def __init__(self, parent=None): QtGui.QMainWindow.__init__(self, parent) self.ui = loadUi(os.path.join(os.getcwd(), "try_ui.ui"), self) self.ui.pushButton.clicked.connect(self.informationMessage) def informationMessage(self): reply = QtGui.QMessageBox.information(self, "QMessageBox.information()", MainWindow.MESSAGE) if __name__ == "__main__": app = QtGui.QApplication(sys.argv) myapp = MainWindow() myapp.show() sys.exit(app.exec_()) </code></pre> <p>You need to include the classes UiLoader and loadUi. They are from: <a href="https://github.com/lunaryorn/snippets/blob/master/qt4/designer/pyside_dynamic.py" rel="nofollow">https://github.com/lunaryorn/snippets/blob/master/qt4/designer/pyside_dynamic.py</a></p> <pre><code>class UiLoader(QtUiTools.QUiLoader): """ Subclass :class:`~PySide.QtUiTools.QUiLoader` to create the user interface in a base instance. Unlike :class:`~PySide.QtUiTools.QUiLoader` itself this class does not create a new instance of the top-level widget, but creates the user interface in an existing instance of the top-level class. This mimics the behaviour of :func:`PyQt4.uic.loadUi`. """ def __init__(self, baseinstance): """ Create a loader for the given ``baseinstance``. The user interface is created in ``baseinstance``, which must be an instance of the top-level class in the user interface to load, or a subclass thereof. ``parent`` is the parent object of this loader. """ QtUiTools.QUiLoader.__init__(self, baseinstance) self.baseinstance = baseinstance def createWidget(self, class_name, parent=None, name=''): if parent is None and self.baseinstance: # supposed to create the top-level widget, return the base instance # instead return self.baseinstance else: # create a new widget for child widgets widget = QtUiTools.QUiLoader.createWidget(self, class_name, parent, name) if self.baseinstance: # set an attribute for the new child widget on the base # instance, just like PyQt4.uic.loadUi does. setattr(self.baseinstance, name, widget) return widget def loadUi(uifile, baseinstance=None): """ Dynamically load a user interface from the given ``uifile``. ``uifile`` is a string containing a file name of the UI file to load. If ``baseinstance`` is ``None``, the a new instance of the top-level widget will be created. Otherwise, the user interface is created within the given ``baseinstance``. In this case ``baseinstance`` must be an instance of the top-level widget class in the UI file to load, or a subclass thereof. In other words, if you've created a ``QMainWindow`` interface in the designer, ``baseinstance`` must be a ``QMainWindow`` or a subclass thereof, too. You cannot load a ``QMainWindow`` UI file with a plain :class:`~PySide.QtGui.QWidget` as ``baseinstance``. :method:`~PySide.QtCore.QMetaObject.connectSlotsByName()` is called on the created user interface, so you can implemented your slots according to its conventions in your widget class. Return ``baseinstance``, if ``baseinstance`` is not ``None``. Otherwise return the newly created instance of the user interface. """ loader = UiLoader(baseinstance) widget = loader.load(uifile) QtCore.QMetaObject.connectSlotsByName(widget) return widget </code></pre>
    singulars
    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.
    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