<?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_usage_snippets</id>
	<title>PySide usage snippets - 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_usage_snippets"/>
	<link rel="alternate" type="text/html" href="https://wiki.labrps.com/index.php?title=PySide_usage_snippets&amp;action=history"/>
	<updated>2026-05-07T15:02:43Z</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_usage_snippets&amp;diff=2155&amp;oldid=prev</id>
		<title>LabRPS: Created page with &quot;== Introduction ==   These are snippets of code that are useful when creating interfaces with PySide.  ==Some useful commands==   {{Code|code= # Here the code to display the icon on the &#039;&#039;&#039;pushButton&#039;&#039;&#039;,  # change the name to another button, (&#039;&#039;&#039;radioButton, checkBox&#039;&#039;&#039;) as well as the path to the icon,         # Displays an icon on the button PushButton        # self.image_01 = &quot;C:\Program Files\LabRPS0.1.0\icone01.png&quot; # he name of the ic...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.labrps.com/index.php?title=PySide_usage_snippets&amp;diff=2155&amp;oldid=prev"/>
		<updated>2024-10-29T20:20:48Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;== Introduction ==   These are snippets of code that are useful when &lt;a href=&quot;/Dialog_creation&quot; title=&quot;Dialog creation&quot;&gt;creating interfaces&lt;/a&gt; with &lt;a href=&quot;/PySide&quot; title=&quot;PySide&quot;&gt;PySide&lt;/a&gt;.  ==Some useful commands==   {{Code|code= # Here the code to display the icon on the &amp;#039;&amp;#039;&amp;#039;pushButton&amp;#039;&amp;#039;&amp;#039;,  # change the name to another button, (&amp;#039;&amp;#039;&amp;#039;radioButton, checkBox&amp;#039;&amp;#039;&amp;#039;) as well as the path to the icon,         # Displays an icon on the button PushButton        # self.image_01 = &amp;quot;C:\Program Files\LabRPS0.1.0\icone01.png&amp;quot; # he name of the ic...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Introduction == &lt;br /&gt;
&lt;br /&gt;
These are snippets of code that are useful when [[Dialog_creation|creating interfaces]] with [[PySide|PySide]].&lt;br /&gt;
&lt;br /&gt;
==Some useful commands== &lt;br /&gt;
&lt;br /&gt;
{{Code|code=&lt;br /&gt;
# Here the code to display the icon on the &amp;#039;&amp;#039;&amp;#039;pushButton&amp;#039;&amp;#039;&amp;#039;, &lt;br /&gt;
# change the name to another button, (&amp;#039;&amp;#039;&amp;#039;radioButton, checkBox&amp;#039;&amp;#039;&amp;#039;) as well as the path to the icon,&lt;br /&gt;
&lt;br /&gt;
       # Displays an icon on the button PushButton&lt;br /&gt;
       # self.image_01 = &amp;quot;C:\Program Files\LabRPS0.1.0\icone01.png&amp;quot; # he name of the icon&lt;br /&gt;
       self.image_01 = path+&amp;quot;icone01.png&amp;quot; # the name of the icon&lt;br /&gt;
       icon01 = QtGui.QIcon() &lt;br /&gt;
       icon01.addPixmap(QtGui.QPixmap(self.image_01),QtGui.QIcon.Normal, QtGui.QIcon.Off)&lt;br /&gt;
       self.pushButton.setIcon(icon01) &lt;br /&gt;
       self.pushButton.setLayoutDirection(QtCore.Qt.RightToLeft) # This command reverses the direction of the button&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# path = LabRPS.ConfigGet(&amp;quot;UserAppData&amp;quot;) # gives the user path&lt;br /&gt;
  path = LabRPS.ConfigGet(&amp;quot;AppHomePath&amp;quot;) # gives the installation path of LabRPS&lt;br /&gt;
&lt;br /&gt;
# This command reverses the horizontal button, right to left&lt;br /&gt;
self.pushButton.setLayoutDirection(QtCore.Qt.RightToLeft) # This command reverses the horizontal button&lt;br /&gt;
&lt;br /&gt;
# Displays an info button&lt;br /&gt;
self.pushButton.setToolTip(_translate(&amp;quot;MainWindow&amp;quot;, &amp;quot;Quitter la fonction&amp;quot;, None)) # Displays an info button&lt;br /&gt;
&lt;br /&gt;
# This function gives a color button&lt;br /&gt;
self.pushButton.setStyleSheet(&amp;quot;background-color: red&amp;quot;) # This function gives a color button&lt;br /&gt;
&lt;br /&gt;
# This function gives a color to the text of the button&lt;br /&gt;
self.pushButton.setStyleSheet(&amp;quot;color : #ff0000&amp;quot;) # This function gives a color to the text of the button&lt;br /&gt;
&lt;br /&gt;
# combinaison des deux, bouton et texte&lt;br /&gt;
self.pushButton.setStyleSheet(&amp;quot;color : #ff0000; background-color : #0000ff;&amp;quot; ) #  combination of the two, button, and text&lt;br /&gt;
&lt;br /&gt;
# replace the icon in the main window&lt;br /&gt;
MainWindow.setWindowIcon(QtGui.QIcon(&amp;#039;C:\Program Files\LabRPS0.1.0\View-C3P.png&amp;#039;))&lt;br /&gt;
&lt;br /&gt;
# connects a lineEdit on execute&lt;br /&gt;
self.lineEdit.returnPressed.connect(self.execute) # connects a lineEdit on &amp;quot;def execute&amp;quot; after validation on enter&lt;br /&gt;
# self.lineEdit.textChanged.connect(self.execute) # connects a lineEdit on &amp;quot;def execute&amp;quot; with each keystroke on the keyboard&lt;br /&gt;
&lt;br /&gt;
# display text in a lineEdit&lt;br /&gt;
self.lineEdit.setText(str(val_X)) # Displays the value in the lineEdit (convert to string)&lt;br /&gt;
&lt;br /&gt;
# extract the string contained in a lineEdit&lt;br /&gt;
 val_X = self.lineEdit.text() # extract the (string) string contained in lineEdit&lt;br /&gt;
 val_X = float(val_X0)        # converted the string to an floating&lt;br /&gt;
 val_X = int(val_X0)          # convert the string to an integer&lt;br /&gt;
&lt;br /&gt;
# This code allows you to change the font and its attributes&lt;br /&gt;
       font = QtGui.QFont()&lt;br /&gt;
       font.setFamily(&amp;quot;Times New Roman&amp;quot;)&lt;br /&gt;
       font.setPointSize(10)&lt;br /&gt;
       font.setWeight(10)&lt;br /&gt;
       font.setBold(True) # same result with tags &amp;quot;&amp;lt;b&amp;gt;your text&amp;lt;/b&amp;gt;&amp;quot; (in quotes)&lt;br /&gt;
       self.label_6.setFont(font)&lt;br /&gt;
       self.label_6.setObjectName(&amp;quot;label_6&amp;quot;)&lt;br /&gt;
       self.label_6.setStyleSheet(&amp;quot;color : #ff0000&amp;quot;) # This function gives a color to the text&lt;br /&gt;
       self.label_6.setText(_translate(&amp;quot;MainWindow&amp;quot;, &amp;quot;Select a view&amp;quot;, None))&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Encoding problems == &lt;br /&gt;
&lt;br /&gt;
=== UTF8 === &lt;br /&gt;
&lt;br /&gt;
By using the characters with accents, where you get the error:&lt;br /&gt;
{{Code|code=&lt;br /&gt;
UnicodeDecodeError: &amp;#039;utf8&amp;#039; codec can&amp;#039;t decode bytes in position 0-2: invalid data&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Several solutions are possible.&lt;br /&gt;
{{Code|code=&lt;br /&gt;
# conversion from a lineEdit&lt;br /&gt;
App.activeDocument().CopyRight.Text = str(unicode(self.lineEdit_20.text() , &amp;#039;ISO-8859-1&amp;#039;).encode(&amp;#039;UTF-8&amp;#039;))&lt;br /&gt;
DESIGNED_BY = unicode(self.lineEdit_01.text(), &amp;#039;ISO-8859-1&amp;#039;).encode(&amp;#039;UTF-8&amp;#039;)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
or with the procedure&lt;br /&gt;
{{Code|code=&lt;br /&gt;
def utf8(unio):&lt;br /&gt;
    return unicode(unio).encode(&amp;#039;UTF8&amp;#039;)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== ASCII ===&lt;br /&gt;
&lt;br /&gt;
{{Code|code=&lt;br /&gt;
UnicodeEncodeError: &amp;#039;ascii&amp;#039; codec can&amp;#039;t encode character u&amp;#039;\xe9&amp;#039; in position 9: ordinal not in range(128)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Code|code=&lt;br /&gt;
# conversion&lt;br /&gt;
a = u&amp;quot;Nom de l&amp;#039;élément : &amp;quot;&lt;br /&gt;
f.write(&amp;#039;&amp;#039;&amp;#039;a.encode(&amp;#039;iso-8859-1&amp;#039;)&amp;#039;&amp;#039;&amp;#039;+str(element_)+&amp;quot;\n&amp;quot;)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
or with the procedure&lt;br /&gt;
{{Code|code=&lt;br /&gt;
def iso8859(encoder):&lt;br /&gt;
    return unicode(encoder).encode(&amp;#039;iso-8859-1&amp;#039;)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
{{Code|code=&lt;br /&gt;
iso8859(unichr(176))&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
{{Code|code=&lt;br /&gt;
unichr(ord(176))&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
{{Code|code=&lt;br /&gt;
uniteSs = &amp;quot;mm&amp;quot;+iso8859(unichr(178))&lt;br /&gt;
print(unicode(uniteSs, &amp;#039;iso8859&amp;#039;))&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>