Python Forum
[PyQt] QIcon not displaying
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] QIcon not displaying
#1
Im running through PyQt5 tuts and came across a couple of tutorials that use QIcon. I cant get anything given to QIcon to work at all whether its through QAction or setting the window icon via...

self.setWindowIcon(QtGui.QIcon('py.png'))   
I tried the following based on google search results:
  • full path
  • changing image formats
  • changing image sizes
  • image in same directory as script


full code:
import sys
from PyQt5.QtWidgets import QMainWindow, QAction, qApp, QApplication
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import QFile


class Example(QMainWindow):
    
    def __init__(self):
        super().__init__()
        
        self.initUI()
        
        
    def initUI(self):               
        print(QFile.exists('py.png'))
        exitAction = QAction(QIcon('/home/metulburr/py.png'), '&Exit', self)        
        exitAction.setShortcut('Ctrl+Q')
        exitAction.setStatusTip('Exit application')
        exitAction.triggered.connect(qApp.quit)

        self.statusBar()

        menubar = self.menuBar()
        fileMenu = menubar.addMenu('&File')
        fileMenu.addAction(exitAction)
        
        self.setGeometry(300, 300, 300, 200)
        self.setWindowTitle('Menubar')    
        self.show()
        
        
if __name__ == '__main__':
    
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())  
Anything given to QIcon is as if the line didnt exist at all. 

Ubuntu 16.04 
My system was acting wacky so i did a complete fresh install again. Maybe i am missing a dependency or something?
Recommended Tutorials:
Reply


Messages In This Thread
QIcon not displaying - by metulburr - May-16-2017, 01:35 AM
RE: QIcon not displaying - by Fred Barclay - May-18-2017, 06:34 AM
RE: QIcon not displaying - by metulburr - May-18-2017, 11:56 AM
RE: QIcon not displaying - by Fred Barclay - May-18-2017, 03:43 PM
RE: QIcon not displaying - by snippsat - May-18-2017, 11:57 AM
RE: QIcon not displaying - by metulburr - May-18-2017, 12:55 PM
RE: QIcon not displaying - by metulburr - May-18-2017, 04:35 PM
RE: QIcon not displaying - by snippsat - May-18-2017, 05:58 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020