How to set system tray title when hovering over app icon

Question:

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

Asked By: ees

||

Answers:

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_())
Answered By: Isma
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.