<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.labrps.com/index.php?action=history&amp;feed=atom&amp;title=PySide_Advanced_Examples</id>
	<title>PySide Advanced Examples - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.labrps.com/index.php?action=history&amp;feed=atom&amp;title=PySide_Advanced_Examples"/>
	<link rel="alternate" type="text/html" href="https://wiki.labrps.com/index.php?title=PySide_Advanced_Examples&amp;action=history"/>
	<updated>2026-06-14T23:24:05Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.38.2</generator>
	<entry>
		<id>https://wiki.labrps.com/index.php?title=PySide_Advanced_Examples&amp;diff=1842&amp;oldid=prev</id>
		<title>LabRPS: Created page with &quot;{{TOCright}}  ==Introduction==   The purpose of this page is to cover advanced  level examples of the PySide GUI manager (there are accompanying pages PySide Beginner Examples and PySide Intermediate Examples).  By using the PySide module from inside LabRPS, you have full control over its interface. You can for example: * Add your own panels, widgets and toolbars * Add or hide elements to existing p...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.labrps.com/index.php?title=PySide_Advanced_Examples&amp;diff=1842&amp;oldid=prev"/>
		<updated>2024-07-26T18:53:08Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{TOCright}}  ==Introduction==   The purpose of this page is to cover advanced  level examples of the &lt;a href=&quot;/PySide&quot; title=&quot;PySide&quot;&gt;PySide&lt;/a&gt; GUI manager (there are accompanying pages &lt;a href=&quot;/PySide_Beginner_Examples&quot; title=&quot;PySide Beginner Examples&quot;&gt;PySide Beginner Examples&lt;/a&gt; and &lt;a href=&quot;/PySide_Intermediate_Examples&quot; title=&quot;PySide Intermediate Examples&quot;&gt;PySide Intermediate Examples&lt;/a&gt;).  By using the PySide module from inside LabRPS, you have full control over its interface. You can for example: * Add your own panels, widgets and toolbars * Add or hide elements to existing p...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{TOCright}}&lt;br /&gt;
&lt;br /&gt;
==Introduction== &lt;br /&gt;
&lt;br /&gt;
The purpose of this page is to cover advanced  level examples of the [[PySide|PySide]] GUI manager (there are accompanying pages [[PySide_Beginner_Examples|PySide Beginner Examples]] and [[PySide_Intermediate_Examples|PySide Intermediate Examples]]).&lt;br /&gt;
&lt;br /&gt;
By using the PySide module from inside LabRPS, you have full control over its interface. You can for example:&lt;br /&gt;
* Add your own panels, widgets and toolbars&lt;br /&gt;
* Add or hide elements to existing panels&lt;br /&gt;
* Change, redirect or add connections between all those elements&lt;br /&gt;
&lt;br /&gt;
==Create Reference to the Main Window== &lt;br /&gt;
&lt;br /&gt;
If you want to work on the LabRPS interface, the very first thing to do is create a reference to the LabRPS main window:&lt;br /&gt;
&lt;br /&gt;
{{Code|code=&lt;br /&gt;
import sys&lt;br /&gt;
from PySide import QtGui ,QtCore &lt;br /&gt;
app = QtGui.qApp&lt;br /&gt;
mw = LabRPSGui.getMainWindow()&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Browse the Children of the Main Window== &lt;br /&gt;
&lt;br /&gt;
Then, you can for example browse through all the widgets of the interface:&lt;br /&gt;
&lt;br /&gt;
{{Code|code=&lt;br /&gt;
for child in mw.children():&lt;br /&gt;
   print(&amp;#039;widget name = &amp;#039;, child.objectName(), &amp;#039;, widget type = &amp;#039;, child)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
The widgets in a Qt interface are usually nested into &amp;quot;container&amp;quot; widgets, so the children of our main window can themselves contain other children. Depending on the widget type, there are a lot of things you can do. Check the API documentation to see what is possible.&lt;br /&gt;
&lt;br /&gt;
==Add New Widget Manually== &lt;br /&gt;
&lt;br /&gt;
Adding a new widget, for example a dockWidget (which can be placed in one of LabRPS&amp;#039;s side panels) is easy:&lt;br /&gt;
&lt;br /&gt;
{{Code|code=&lt;br /&gt;
myWidget = QtGui.QDockWidget()&lt;br /&gt;
mw.addDockWidget(QtCore.Qt.RightDockWidgetArea,myWidget)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
You could then add stuff directly to your widget:&lt;br /&gt;
&lt;br /&gt;
{{Code|code=&lt;br /&gt;
myWidget.setObjectName(&amp;quot;my Nice New Widget&amp;quot;)&lt;br /&gt;
myWidget.resize(QtCore.QSize(300,100)) # sets size of the widget&lt;br /&gt;
label = QtGui.QLabel(&amp;quot;Hello World&amp;quot;, myWidget) # creates a label&lt;br /&gt;
label.setGeometry(QtCore.QRect(2,50,200,24))  # sets its size&lt;br /&gt;
label.setObjectName(&amp;quot;myLabel&amp;quot;) # sets its name, so it can be found by name&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Add New Widget by Creating UI Object== &lt;br /&gt;
&lt;br /&gt;
But a preferred method is to create a UI object which will do all of the setup of your widget at once. The big advantage is that such an UI object can be [[Dialog_creation|created graphically]] with the Qt Designer program. A typical object generated by Qt Designer is like this:&lt;br /&gt;
&lt;br /&gt;
{{Code|code=&lt;br /&gt;
class myWidget_Ui(object):&lt;br /&gt;
  def setupUi(self, myWidget):&lt;br /&gt;
    myWidget.setObjectName(&amp;quot;my Nice New Widget&amp;quot;)&lt;br /&gt;
    myWidget.resize(QtCore.QSize(300,100).expandedTo(myWidget.minimumSizeHint())) # sets size of the widget&lt;br /&gt;
&lt;br /&gt;
    self.label = QtGui.QLabel(myWidget) # creates a label&lt;br /&gt;
    self.label.setGeometry(QtCore.QRect(50,50,200,24)) # sets its size&lt;br /&gt;
    self.label.setObjectName(&amp;quot;label&amp;quot;) # sets its name, so it can be found by name&lt;br /&gt;
&lt;br /&gt;
  def retranslateUi(self, draftToolbar): # built-in QT function that manages translations of widgets&lt;br /&gt;
    myWidget.setWindowTitle(QtGui.QApplication.translate(&amp;quot;myWidget&amp;quot;, &amp;quot;My Widget&amp;quot;, None, QtGui.QApplication.UnicodeUTF8))&lt;br /&gt;
    self.label.setText(QtGui.QApplication.translate(&amp;quot;myWidget&amp;quot;, &amp;quot;Welcome to my new widget!&amp;quot;, None, QtGui.QApplication.UnicodeUTF8))&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
To use it, you just need to apply it to your freshly created widget like this:&lt;br /&gt;
&lt;br /&gt;
{{Code|code=&lt;br /&gt;
app = QtGui.qApp&lt;br /&gt;
FCmw = app.activeWindow()&lt;br /&gt;
myNewLabRPSWidget = QtGui.QDockWidget() # create a new dckwidget&lt;br /&gt;
myNewLabRPSWidget.ui = myWidget_Ui() # load the Ui script&lt;br /&gt;
myNewLabRPSWidget.ui.setupUi(myNewLabRPSWidget) # setup the ui&lt;br /&gt;
FCmw.addDockWidget(QtCore.Qt.RightDockWidgetArea,myNewLabRPSWidget) # add the widget to the main window&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Loading the UI from a Qt Designer .ui File== &lt;br /&gt;
&lt;br /&gt;
The key to loading a UI file successfully is to use the full path to the file. As an example, the [[Std_AddonMgr|Addon Manager]] does it like this:&lt;br /&gt;
&lt;br /&gt;
{{Code|code=&lt;br /&gt;
self.dialog = LabRPSGui.PySideUic.loadUi(os.path.join(os.path.dirname(__file__), &amp;quot;AddonManager.ui&amp;quot;))&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Powerdocnavi}}&lt;br /&gt;
[[Category:Developer Documentation]]&lt;br /&gt;
[[Category:Python Code]]&lt;br /&gt;
{{clear}}&lt;/div&gt;</summary>
		<author><name>LabRPS</name></author>
	</entry>
</feed>