Difference between revisions of "Documentation/4.0/Developers/Tutorials/PythonAndUIFile"
From Slicer Wiki
(Created page with 'This tutorial will demonstrate how UI file created using QtDesigner can be loaded and used from a python script loaded using the Slicer python interactor. As depicted below, let…') |
(No difference)
|
Revision as of 22:45, 15 February 2011
Home < Documentation < 4.0 < Developers < Tutorials < PythonAndUIFileThis tutorial will demonstrate how UI file created using QtDesigner can be loaded and used from a python script loaded using the Slicer python interactor.
As depicted below, let's assume you created a UI file where a QLineEdit and QPushButton are layout horizontally.
Loading the UI file and accessing the associated objects can be done using QUILoader.
The following code snippet aims at loading the UI file and connecting the associated QPushButton and QLineEdit.
# Load UI file uiloader = qt.QUiLoader() file = qt.QFile("/home/jchris/Projects/sandbox/qSlicerLineEditWidget.ui") file.open(qt.QFile.ReadOnly) line_edit_widget = uiloader.load(file) file.close() # Get references to both the QPushButton and the QLineEdit clear_button = line_edit_widget.findChild(qt.QPushButton, 'ClearButton') line_edit = line_edit_widget.findChild(qt.QLineEdit, 'LineEdit') clear_button.connect('clicked()', line_edit, 'clear()') line_edit_widget.show()