How can I add an icon to a window GUI?

Need help, or want to share a macro? Post here!
CMT
Posts: 15
Joined: Thu Jan 24, 2019 7:00 pm

How can I add an icon to a window GUI?

Postby CMT » Tue Feb 05, 2019 11:08 pm

For example in this Code :

Code: Select all

from PySide import QtGui, QtCore

class Example(QtGui.QDialog):
	""""""
	def __init__(self):
		super(Example, self).__init__()
		self.initUI()
		
	def initUI(self):
		# create our window
		# define window		xLoc,yLoc,xDim,yDim
		self.setGeometry(	300, 200, 300, 350)
		self.setWindowTitle("Example")
		self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
        # create some Labels
		self.label1 = QtGui.QLabel("",self)
		self.label1.move(70,25)
		self.label2 = QtGui.QLabel("",self)
		self.label2.move(115,25)
		self.label3 = QtGui.QLabel("",self)
		self.label3.move(160,25)
		# text input field
		self.textInput1 = QtGui.QLineEdit(self)
		self.textInput1.setText("")
		self.textInput1.setFixedWidth(35)
		self.textInput1.move(55,40)
		self.textInput2 = QtGui.QLineEdit(self)
		self.textInput2.setText("")
		self.textInput2.setFixedWidth(35)
		self.textInput2.move(100,40)
		self.textInput3 = QtGui.QLineEdit(self)
		self.textInput3.setText("")
		self.textInput3.setFixedWidth(35)
		self.textInput3.move(145,40)
		# ok button
		okButton = QtGui.QPushButton("Ok", self)
		okButton.clicked.connect(self.onOk)
		okButton.move(170,320)	
		
		# now make the window visible
		self.show()
	def onOk(self):
		self.result	= userOk
		
		
		
# Constant definitions
userOk		= "Ok"

# code ***********************************************************************************
form = Example()
form.exec_()
if form.result==userOk:
	pass
 # steps to handle user clicking Cancel

How can i add a new icon in this window ??
mario52
Posts: 2449
Joined: Wed May 16, 2012 2:13 pm

Re: How can I add an icon to a window GUI?

Postby mario52 » Wed Feb 06, 2019 6:09 pm

Maybe you need a special feature, go into Macros_recipes and Code_snippets. My macros on Gist.github
CMT
Posts: 15
Joined: Thu Jan 24, 2019 7:00 pm

Re: How can I add an icon to a window GUI?

Postby CMT » Wed Feb 20, 2019 9:42 pm

mario52 wrote:
Wed Feb 06, 2019 6:09 pm
hi

see Qt_Example, Dialog_creation

mario
Hi i have seen it but it didn't work, can you find the solution for this?

Code: Select all

from PySide import QtGui, QtCore
class Test(QtGui.QDialog):
	""""""
	def __init__(self):
		super(Test, self).__init__()
		self.initUI()
	def initUI(self):
		# create our window
		# define window	 xLoc,yLoc,xDim,yDim
		self.setGeometry(300, 200, 350, 100)
		self.setMinimumSize(350,400)
		self.setMaximumSize(350,100)		
		self.setWindowTitle("Library")
		self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
		#self.image_01 = "C:\Program Files\FreeCAD 0.17\IconeLIBFACOD\Icone.png" 
        	self.image_01 = path+"Icone.png" # adapter le nom de l'icne
        	Icone = QtGui.QIcon() 
        	Icone.addPixmap(QtGui.QPixmap(self.image_01),QtGui.QIcon.Normal, QtGui.QIcon.ON)
		Icone.move(270,39)
		self.show()
form = Test()
form.exec_()