Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. How to set an icon for an exe file using pyinstaller

How to set an icon for an exe file using pyinstaller

Scheduled Pinned Locked Moved Unsolved Qt for Python
2 Posts 2 Posters 12.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LT-K101
    wrote on 25 Aug 2022, 11:18 last edited by
    #1

    Hi,
    I'm having an issue with setting an icon for exe file. When I run this command the icon set for the .exe file does not show after the compilation. pyinstaller EDS_main.py --onefile --windowed --icon=transparent.ico . Any help with what I'm wrong thanks in advance.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DieterV
      wrote on 25 Aug 2022, 11:51 last edited by
      #2

      I quote from this great page:

      The icon used for the window isn't determined by the icons in the executable file, but by the application itself. To show an icon on our window we need to modify our simple application a little bit, to add a call to .setWindowIcon().
      python

      from PyQt6 import QtWidgets, QtGui
      import sys
      
      class MainWindow(QtWidgets.QMainWindow):
      
          def __init__(self):
              super().__init__()
      
              self.setWindowTitle("Hello World")
              l = QtWidgets.QLabel("My simple app.")
              l.setMargin(10)
              self.setCentralWidget(l)
              self.show()
      
      if __name__ == '__main__':
          app = QtWidgets.QApplication(sys.argv)
          app.setWindowIcon(QtGui.QIcon('hand.ico'))
          w = MainWindow()
          app.exec()
      

      Here we've added the .setWindowIcon call to the app instance. This defines a default icon to be used for all windows of our application. You can override this on a per-window basis if you like, by calling .setWindowIcon on the window itself.

      1 Reply Last reply
      1

      1/2

      25 Aug 2022, 11:18

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved