junsu February 2016

Window icon does not show

I study this tutorial http://zetcode.com/gui/pyqt5/firstprograms/ and code here.

import sys
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.QtGui import QIcon


class Example(QWidget):

    def __init__(self):
        super().__init__()

        self.initUI()


    def initUI(self):

        self.setGeometry(300, 300, 300, 220)
        self.setWindowTitle('Icon')
        self.setWindowIcon(QIcon('web.png'))        

        self.show()


if __name__ == '__main__':

    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())  

Can I show Window icon? I use PyQt5, Python3.4 and Linuxmint 17.2 cinnamon.

This Window

Answers


Antoine February 2016

Check where the icon file is placed. It should be placed in the execution directory in your case. You can check the execution directroy with the following change:

if __name__ == '__main__':
    import os
    print("Work dir:" + os.getcwd())

    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())  


Antoine February 2016

try PySide.QtGui.QApplication.setWindowIcon(icon). Like this:

if __name__ == '__main__':
    app = QApplication(sys.argv)
    app.setWindowIcon(QIcon('web.png'))
    ex = Example()
    sys.exit(app.exec_())  


a_manthey_67 February 2016

i am not sure, what you expected: the windowicon is shown as applicationIcon (e.g. here on ubuntu gnome, see my code in the background)

enter image description here

If no icon has been set, windowIcon() returns the application icon

(QApplication::windowIcon()).

http://doc.qt.io/qt-5/qwidget.html#windowIcon-prop

looks on ubuntu like this:

enter image description here

so i think, the code is working correctly

Post Status

Asked in February 2016
Viewed 2,086 times
Voted 14
Answered 3 times

Search




Leave an answer