2

I'd like to change the hover-over title of my app icon; such that, in the picture below, it reads "FOO" instead of "python". I'm showing the code I've used to import the app icon, and am thinking if there's a way, it must be a one liner underneath this. Anyone know?

if __name__ == '__main__':

    app = QtGui.QApplication.instance()
    if app is None:
        app = QtGui.QApplication([])

    # set app icon for tray:
    pyDir = os.path.dirname(os.path.abspath(__file__)) #python file location
    iconDir = os.path.join(pyDir, 'icons')
    app_icon = QtGui.QIcon()
    app_icon.addFile(os.path.join(iconDir, '256x256.png'), QtCore.QSize(256,256))
    app.setWindowIcon(app_icon)
    #should be a one-liner here?? app.setWindowIconTitle, etc?

    w = MainWindow()
    sys.exit(app.exec_())

Image:

icon title

Isma
  • 14,604
  • 5
  • 37
  • 51
ees
  • 327
  • 1
  • 17

1 Answers1

1

Try by setting the app name as follows:

QCoreApplication.setApplicationName('FOO')

You can also add a title to your window, e.g.:

import sys

from PyQt5 import QtGui, QtCore
from PyQt5.QtWidgets import QMainWindow, QApplication

if __name__ == '__main__':

    app = QApplication([])

    # set app icon for tray:
    pyDir = os.path.dirname(os.path.abspath(__file__))
    iconDir = os.path.join(pyDir, 'icons')
    app_icon = QtGui.QIcon()
    app_icon.addFile(os.path.join(iconDir, '256x256.png'), QtCore.QSize(256,256))
    app.setWindowIcon(app_icon)

    w = QMainWindow()
    w.setWindowTitle("FOO")

    w.show()
    sys.exit(app.exec_())
Isma
  • 14,604
  • 5
  • 37
  • 51
  • thanks @Isma, but I can't seem to get this to work on macOS pyqt4... I've also tried `app.setApplicationName("FOO")`, `QtGui.qApp.setApplicationName("FOO")`, and `QtCore.QCoreApplication.setApplicationName("FOO")` all independently... no errors, but also doesn't change the text. – ees Feb 17 '19 at 01:17
  • 1
    Yes, you are right, still not working on a Mac, it seems you have to do it when you generate the package https://stackoverflow.com/questions/7827430/setting-mac-osx-application-menu-menu-bar-item-to-other-than-python-in-my-pyth – Isma Feb 17 '19 at 17:46
  • oof, how unfortunate. I'll accept your answer, but for anyone else looking, please note this is the non-mac solution – ees Feb 17 '19 at 22:50