How can I add an icon to a window GUI?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
CMT
Posts: 16
Joined: Thu Jan 24, 2019 7:00 pm

How can I add an icon to a window GUI?

Post by CMT »

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
Veteran
Posts: 4673
Joined: Wed May 16, 2012 2:13 pm

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

Post by mario52 »

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

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

Post by CMT »

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_()
mario52
Veteran
Posts: 4673
Joined: Wed May 16, 2012 2:13 pm

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

Post by mario52 »

hi

here example we create a window with a QLabel() text + image

Code: Select all

import PySide
from PySide import QtGui ,QtCore
from PySide.QtGui import QPixmap, QMovie, QLabel
from PySide.QtCore import *
class MyLabelPatience():
    label = QtGui.QLabel()
    label.setText("<img src=" + path_Name_Image + "><b><center>Wait please</center> \n\n<center>i search the fonts !\n\n</center></b>")
    # center screen
    ecran = FreeCADGui.getMainWindow().frameGeometry()
    xF = 250; yF = 120
    xW = (ecran.width()/2) - (xF/2)
    yW = (ecran.height()/2)- (yF/2)
    label.setGeometry(xW, yW, xF, yF)
    ####
    label.setStyleSheet("QLabel {background-color : #F0C300;font: 12pt; }");
    label.setWindowFlags(Qt.WindowFlags(Qt.FramelessWindowHint))        # pas de bords
#    ### un-comment for use ###############
#    movie = QtGui.QMovie(path_Name_Image)    # anime le fichier Gif anime (decommenter)
#    label.setMovie(movie)
#    movie.start()
#    ##################

patience = MyLabelPatience().label
patience.show()
#patience.close()
#MyLabelPatience().movie.start()
#MyLabelPatience().movie.stop()

Image


but with the animated gif I not see the text!
Image

EDIT :11/06/2019 11h57 Paris : code in Class
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
Post Reply