QSystemTrayIcon not showing












0














Using Kubuntu 18.04 (qt5 5.9.5), Python 3.6. I can't get this code to show the tray icon; other icons like Dropbox, etc. are shown, but this not:



import sys

from PyQt5.QtWidgets import QApplication, QMenu, QSystemTrayIcon, qApp, QMessageBox
from PyQt5.QtGui import QIcon


def run_something():
print("Running something...")


if __name__ == '__main__':

print("Creating application...")
app = QApplication(sys.argv)

print("Creating menu...")
menu = QMenu()
checkAction = menu.addAction("Check Now")
checkAction.triggered.connect(run_something)
quitAction = menu.addAction("Quit")
quitAction.triggered.connect(qApp.quit)

print("Creating icon...")
icon = QIcon.fromTheme("system-help")

print("Creating tray...")
trayIcon = QSystemTrayIcon(icon, app)
trayIcon.setContextMenu(menu)

print("Showing tray...")
trayIcon.show()
trayIcon.setToolTip("unko!")
trayIcon.showMessage("hoge", "moge")

print("Running application...")
sys.exit(app.exec_())


The message ("hoge", "moge") is shown, but I can't find the icon anywhere... Neither in the left upper corner, as other post says.










share|improve this question
























  • QIcon QIcon::fromTheme(const QString &name, const QIcon &fallback) Returns the QIcon corresponding to name in the current icon theme. If no such icon is found in the current theme fallback is returned instead. If you want to provide a guaranteed fallback for platforms that do not support theme icons, you can use the second argument : icon = QIcon.fromTheme("system-help", QIcon('branch-end.png'))
    – S. Nick
    Nov 22 at 23:44










  • Thanks @S.Nick, also tried with a local icon without success.
    – okelet
    Nov 23 at 7:14










  • Sorry, everything works in Windows 10.
    – S. Nick
    Nov 23 at 7:36










  • Also tried with a clean installation of Kubuntu 18.10, same results.
    – okelet
    Nov 23 at 10:45
















0














Using Kubuntu 18.04 (qt5 5.9.5), Python 3.6. I can't get this code to show the tray icon; other icons like Dropbox, etc. are shown, but this not:



import sys

from PyQt5.QtWidgets import QApplication, QMenu, QSystemTrayIcon, qApp, QMessageBox
from PyQt5.QtGui import QIcon


def run_something():
print("Running something...")


if __name__ == '__main__':

print("Creating application...")
app = QApplication(sys.argv)

print("Creating menu...")
menu = QMenu()
checkAction = menu.addAction("Check Now")
checkAction.triggered.connect(run_something)
quitAction = menu.addAction("Quit")
quitAction.triggered.connect(qApp.quit)

print("Creating icon...")
icon = QIcon.fromTheme("system-help")

print("Creating tray...")
trayIcon = QSystemTrayIcon(icon, app)
trayIcon.setContextMenu(menu)

print("Showing tray...")
trayIcon.show()
trayIcon.setToolTip("unko!")
trayIcon.showMessage("hoge", "moge")

print("Running application...")
sys.exit(app.exec_())


The message ("hoge", "moge") is shown, but I can't find the icon anywhere... Neither in the left upper corner, as other post says.










share|improve this question
























  • QIcon QIcon::fromTheme(const QString &name, const QIcon &fallback) Returns the QIcon corresponding to name in the current icon theme. If no such icon is found in the current theme fallback is returned instead. If you want to provide a guaranteed fallback for platforms that do not support theme icons, you can use the second argument : icon = QIcon.fromTheme("system-help", QIcon('branch-end.png'))
    – S. Nick
    Nov 22 at 23:44










  • Thanks @S.Nick, also tried with a local icon without success.
    – okelet
    Nov 23 at 7:14










  • Sorry, everything works in Windows 10.
    – S. Nick
    Nov 23 at 7:36










  • Also tried with a clean installation of Kubuntu 18.10, same results.
    – okelet
    Nov 23 at 10:45














0












0








0







Using Kubuntu 18.04 (qt5 5.9.5), Python 3.6. I can't get this code to show the tray icon; other icons like Dropbox, etc. are shown, but this not:



import sys

from PyQt5.QtWidgets import QApplication, QMenu, QSystemTrayIcon, qApp, QMessageBox
from PyQt5.QtGui import QIcon


def run_something():
print("Running something...")


if __name__ == '__main__':

print("Creating application...")
app = QApplication(sys.argv)

print("Creating menu...")
menu = QMenu()
checkAction = menu.addAction("Check Now")
checkAction.triggered.connect(run_something)
quitAction = menu.addAction("Quit")
quitAction.triggered.connect(qApp.quit)

print("Creating icon...")
icon = QIcon.fromTheme("system-help")

print("Creating tray...")
trayIcon = QSystemTrayIcon(icon, app)
trayIcon.setContextMenu(menu)

print("Showing tray...")
trayIcon.show()
trayIcon.setToolTip("unko!")
trayIcon.showMessage("hoge", "moge")

print("Running application...")
sys.exit(app.exec_())


The message ("hoge", "moge") is shown, but I can't find the icon anywhere... Neither in the left upper corner, as other post says.










share|improve this question















Using Kubuntu 18.04 (qt5 5.9.5), Python 3.6. I can't get this code to show the tray icon; other icons like Dropbox, etc. are shown, but this not:



import sys

from PyQt5.QtWidgets import QApplication, QMenu, QSystemTrayIcon, qApp, QMessageBox
from PyQt5.QtGui import QIcon


def run_something():
print("Running something...")


if __name__ == '__main__':

print("Creating application...")
app = QApplication(sys.argv)

print("Creating menu...")
menu = QMenu()
checkAction = menu.addAction("Check Now")
checkAction.triggered.connect(run_something)
quitAction = menu.addAction("Quit")
quitAction.triggered.connect(qApp.quit)

print("Creating icon...")
icon = QIcon.fromTheme("system-help")

print("Creating tray...")
trayIcon = QSystemTrayIcon(icon, app)
trayIcon.setContextMenu(menu)

print("Showing tray...")
trayIcon.show()
trayIcon.setToolTip("unko!")
trayIcon.showMessage("hoge", "moge")

print("Running application...")
sys.exit(app.exec_())


The message ("hoge", "moge") is shown, but I can't find the icon anywhere... Neither in the left upper corner, as other post says.







python python-3.x ubuntu pyqt qsystemtrayicon






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 at 22:49









eyllanesc

73.4k103056




73.4k103056










asked Nov 22 at 22:22









okelet

332212




332212












  • QIcon QIcon::fromTheme(const QString &name, const QIcon &fallback) Returns the QIcon corresponding to name in the current icon theme. If no such icon is found in the current theme fallback is returned instead. If you want to provide a guaranteed fallback for platforms that do not support theme icons, you can use the second argument : icon = QIcon.fromTheme("system-help", QIcon('branch-end.png'))
    – S. Nick
    Nov 22 at 23:44










  • Thanks @S.Nick, also tried with a local icon without success.
    – okelet
    Nov 23 at 7:14










  • Sorry, everything works in Windows 10.
    – S. Nick
    Nov 23 at 7:36










  • Also tried with a clean installation of Kubuntu 18.10, same results.
    – okelet
    Nov 23 at 10:45


















  • QIcon QIcon::fromTheme(const QString &name, const QIcon &fallback) Returns the QIcon corresponding to name in the current icon theme. If no such icon is found in the current theme fallback is returned instead. If you want to provide a guaranteed fallback for platforms that do not support theme icons, you can use the second argument : icon = QIcon.fromTheme("system-help", QIcon('branch-end.png'))
    – S. Nick
    Nov 22 at 23:44










  • Thanks @S.Nick, also tried with a local icon without success.
    – okelet
    Nov 23 at 7:14










  • Sorry, everything works in Windows 10.
    – S. Nick
    Nov 23 at 7:36










  • Also tried with a clean installation of Kubuntu 18.10, same results.
    – okelet
    Nov 23 at 10:45
















QIcon QIcon::fromTheme(const QString &name, const QIcon &fallback) Returns the QIcon corresponding to name in the current icon theme. If no such icon is found in the current theme fallback is returned instead. If you want to provide a guaranteed fallback for platforms that do not support theme icons, you can use the second argument : icon = QIcon.fromTheme("system-help", QIcon('branch-end.png'))
– S. Nick
Nov 22 at 23:44




QIcon QIcon::fromTheme(const QString &name, const QIcon &fallback) Returns the QIcon corresponding to name in the current icon theme. If no such icon is found in the current theme fallback is returned instead. If you want to provide a guaranteed fallback for platforms that do not support theme icons, you can use the second argument : icon = QIcon.fromTheme("system-help", QIcon('branch-end.png'))
– S. Nick
Nov 22 at 23:44












Thanks @S.Nick, also tried with a local icon without success.
– okelet
Nov 23 at 7:14




Thanks @S.Nick, also tried with a local icon without success.
– okelet
Nov 23 at 7:14












Sorry, everything works in Windows 10.
– S. Nick
Nov 23 at 7:36




Sorry, everything works in Windows 10.
– S. Nick
Nov 23 at 7:36












Also tried with a clean installation of Kubuntu 18.10, same results.
– okelet
Nov 23 at 10:45




Also tried with a clean installation of Kubuntu 18.10, same results.
– okelet
Nov 23 at 10:45












2 Answers
2






active

oldest

votes


















1














Try PySide2. I just got PySimpleGUIQt running with QSystemTrayIcon today on Linux and Windows with PySide2. Maybe you'll have better luck there?






share|improve this answer





























    0














    No idea why, but this code works, sing PySide2 (basically is the same code than above...):



    import logging
    import sys

    from PySide2.QtGui import QIcon
    from PySide2.QtWidgets import QSystemTrayIcon, QMenu, QApplication, QAction, QMessageBox


    def run_something():
    print("Running something...")


    def show_message():
    msg = QMessageBox()
    msg.setIcon(QMessageBox.Information)

    msg.setWindowTitle("MessageBox demo")
    msg.setText("This is a message box")

    msg.setInformativeText("This is additional information")
    msg.setDetailedText("The details are as follows:")
    msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
    msg.exec_()


    def show_tray_message(tray: QSystemTrayIcon):
    tray.showMessage("Hoooo", "Message from tray")


    if __name__ == '__main__':

    app = QApplication()
    app.setQuitOnLastWindowClosed(False)

    tray = QSystemTrayIcon(QIcon("acorn.png"), app)
    menu = QMenu()

    action_test = QAction("Show a message box")
    action_test.triggered.connect(show_message)
    menu.addAction(action_test)

    action_tray_message = QAction("Show a message from tray")
    action_tray_message.triggered.connect(lambda: show_tray_message(tray))
    menu.addAction(action_tray_message)

    action_exit = QAction("Exit")
    action_exit.triggered.connect(app.exit)
    menu.addAction(action_exit)

    tray.setContextMenu(menu)
    tray.setToolTip("Tool tip")
    tray.show()

    sys.exit(app.exec_())





    share|improve this answer





















    • Also tested using QIcon.fromTheme("system-help").
      – okelet
      Nov 26 at 18:33











    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438605%2fqsystemtrayicon-not-showing%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Try PySide2. I just got PySimpleGUIQt running with QSystemTrayIcon today on Linux and Windows with PySide2. Maybe you'll have better luck there?






    share|improve this answer


























      1














      Try PySide2. I just got PySimpleGUIQt running with QSystemTrayIcon today on Linux and Windows with PySide2. Maybe you'll have better luck there?






      share|improve this answer
























        1












        1








        1






        Try PySide2. I just got PySimpleGUIQt running with QSystemTrayIcon today on Linux and Windows with PySide2. Maybe you'll have better luck there?






        share|improve this answer












        Try PySide2. I just got PySimpleGUIQt running with QSystemTrayIcon today on Linux and Windows with PySide2. Maybe you'll have better luck there?







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 25 at 17:29









        MikeyB

        69359




        69359

























            0














            No idea why, but this code works, sing PySide2 (basically is the same code than above...):



            import logging
            import sys

            from PySide2.QtGui import QIcon
            from PySide2.QtWidgets import QSystemTrayIcon, QMenu, QApplication, QAction, QMessageBox


            def run_something():
            print("Running something...")


            def show_message():
            msg = QMessageBox()
            msg.setIcon(QMessageBox.Information)

            msg.setWindowTitle("MessageBox demo")
            msg.setText("This is a message box")

            msg.setInformativeText("This is additional information")
            msg.setDetailedText("The details are as follows:")
            msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
            msg.exec_()


            def show_tray_message(tray: QSystemTrayIcon):
            tray.showMessage("Hoooo", "Message from tray")


            if __name__ == '__main__':

            app = QApplication()
            app.setQuitOnLastWindowClosed(False)

            tray = QSystemTrayIcon(QIcon("acorn.png"), app)
            menu = QMenu()

            action_test = QAction("Show a message box")
            action_test.triggered.connect(show_message)
            menu.addAction(action_test)

            action_tray_message = QAction("Show a message from tray")
            action_tray_message.triggered.connect(lambda: show_tray_message(tray))
            menu.addAction(action_tray_message)

            action_exit = QAction("Exit")
            action_exit.triggered.connect(app.exit)
            menu.addAction(action_exit)

            tray.setContextMenu(menu)
            tray.setToolTip("Tool tip")
            tray.show()

            sys.exit(app.exec_())





            share|improve this answer





















            • Also tested using QIcon.fromTheme("system-help").
              – okelet
              Nov 26 at 18:33
















            0














            No idea why, but this code works, sing PySide2 (basically is the same code than above...):



            import logging
            import sys

            from PySide2.QtGui import QIcon
            from PySide2.QtWidgets import QSystemTrayIcon, QMenu, QApplication, QAction, QMessageBox


            def run_something():
            print("Running something...")


            def show_message():
            msg = QMessageBox()
            msg.setIcon(QMessageBox.Information)

            msg.setWindowTitle("MessageBox demo")
            msg.setText("This is a message box")

            msg.setInformativeText("This is additional information")
            msg.setDetailedText("The details are as follows:")
            msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
            msg.exec_()


            def show_tray_message(tray: QSystemTrayIcon):
            tray.showMessage("Hoooo", "Message from tray")


            if __name__ == '__main__':

            app = QApplication()
            app.setQuitOnLastWindowClosed(False)

            tray = QSystemTrayIcon(QIcon("acorn.png"), app)
            menu = QMenu()

            action_test = QAction("Show a message box")
            action_test.triggered.connect(show_message)
            menu.addAction(action_test)

            action_tray_message = QAction("Show a message from tray")
            action_tray_message.triggered.connect(lambda: show_tray_message(tray))
            menu.addAction(action_tray_message)

            action_exit = QAction("Exit")
            action_exit.triggered.connect(app.exit)
            menu.addAction(action_exit)

            tray.setContextMenu(menu)
            tray.setToolTip("Tool tip")
            tray.show()

            sys.exit(app.exec_())





            share|improve this answer





















            • Also tested using QIcon.fromTheme("system-help").
              – okelet
              Nov 26 at 18:33














            0












            0








            0






            No idea why, but this code works, sing PySide2 (basically is the same code than above...):



            import logging
            import sys

            from PySide2.QtGui import QIcon
            from PySide2.QtWidgets import QSystemTrayIcon, QMenu, QApplication, QAction, QMessageBox


            def run_something():
            print("Running something...")


            def show_message():
            msg = QMessageBox()
            msg.setIcon(QMessageBox.Information)

            msg.setWindowTitle("MessageBox demo")
            msg.setText("This is a message box")

            msg.setInformativeText("This is additional information")
            msg.setDetailedText("The details are as follows:")
            msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
            msg.exec_()


            def show_tray_message(tray: QSystemTrayIcon):
            tray.showMessage("Hoooo", "Message from tray")


            if __name__ == '__main__':

            app = QApplication()
            app.setQuitOnLastWindowClosed(False)

            tray = QSystemTrayIcon(QIcon("acorn.png"), app)
            menu = QMenu()

            action_test = QAction("Show a message box")
            action_test.triggered.connect(show_message)
            menu.addAction(action_test)

            action_tray_message = QAction("Show a message from tray")
            action_tray_message.triggered.connect(lambda: show_tray_message(tray))
            menu.addAction(action_tray_message)

            action_exit = QAction("Exit")
            action_exit.triggered.connect(app.exit)
            menu.addAction(action_exit)

            tray.setContextMenu(menu)
            tray.setToolTip("Tool tip")
            tray.show()

            sys.exit(app.exec_())





            share|improve this answer












            No idea why, but this code works, sing PySide2 (basically is the same code than above...):



            import logging
            import sys

            from PySide2.QtGui import QIcon
            from PySide2.QtWidgets import QSystemTrayIcon, QMenu, QApplication, QAction, QMessageBox


            def run_something():
            print("Running something...")


            def show_message():
            msg = QMessageBox()
            msg.setIcon(QMessageBox.Information)

            msg.setWindowTitle("MessageBox demo")
            msg.setText("This is a message box")

            msg.setInformativeText("This is additional information")
            msg.setDetailedText("The details are as follows:")
            msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
            msg.exec_()


            def show_tray_message(tray: QSystemTrayIcon):
            tray.showMessage("Hoooo", "Message from tray")


            if __name__ == '__main__':

            app = QApplication()
            app.setQuitOnLastWindowClosed(False)

            tray = QSystemTrayIcon(QIcon("acorn.png"), app)
            menu = QMenu()

            action_test = QAction("Show a message box")
            action_test.triggered.connect(show_message)
            menu.addAction(action_test)

            action_tray_message = QAction("Show a message from tray")
            action_tray_message.triggered.connect(lambda: show_tray_message(tray))
            menu.addAction(action_tray_message)

            action_exit = QAction("Exit")
            action_exit.triggered.connect(app.exit)
            menu.addAction(action_exit)

            tray.setContextMenu(menu)
            tray.setToolTip("Tool tip")
            tray.show()

            sys.exit(app.exec_())






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 26 at 18:32









            okelet

            332212




            332212












            • Also tested using QIcon.fromTheme("system-help").
              – okelet
              Nov 26 at 18:33


















            • Also tested using QIcon.fromTheme("system-help").
              – okelet
              Nov 26 at 18:33
















            Also tested using QIcon.fromTheme("system-help").
            – okelet
            Nov 26 at 18:33




            Also tested using QIcon.fromTheme("system-help").
            – okelet
            Nov 26 at 18:33


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438605%2fqsystemtrayicon-not-showing%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            What visual should I use to simply compare current year value vs last year in Power BI desktop

            Alexandru Averescu

            Trompette piccolo