I want to make image in my QMainWindow so when you click on it you have a signal translating like qpushbutton I use this:
self.quit=QtGui.QPushButton(self)
self.quit.setIcon(QtGui.QIcon('images/9.bmp'))
But the problem is whene I resize the window qpushbutton resized too but not his icon,
Qt won’t stretch your image for you – and it’s best this way. I recommend to keep the pushbutton of a constant size by adding stretchers to the layout holding it. A resizable pushbutton isn’t very appealing visually, and is uncommon in GUIs, anyway.
To make a clickable image, here’s the simplest code I can think of:
Just replace
image.pngwith your image filename (acceptable format by QPixmap) and you’re set.