Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Application with overlay and trayicon but no mainwindow
QtWS25 Last Chance

Application with overlay and trayicon but no mainwindow

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 3 Posters 957 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.
  • T Offline
    T Offline
    Tyskie
    wrote on last edited by
    #1

    Hello,
    I am creating an application with few overlays (just Qframes with transparent/translucent background).
    But I do not want to have a QMainWindow as the "entry point" (not sure how to call it, but the first widget to show) of my app.

    Would it be fine/acceptable to just have a QSystemTrayIcon() and attach the QFrames to this QSystemTrayIcon ?

    for example (pyqt5):

    # imports ....
    
    class MySystemTrayIcon(QSystemTrayIcon):
        def __init__(self, ...):
            super(...)
            self.overlay_1 = MyQFrame(self)
            self.overlay_2 = MyQFrame(self)
            [...]
    
    if __name__ == '__main__':
        app = QApplication(sys.argv)
        tray_icon = MySystemTrayIcon()
        tray_icon.setIcon(QIcon(':/images/icon.png'))
        tray_icon.show()
        sys.exit(app.exec_())
    
    1 Reply Last reply
    0
    • T Offline
      T Offline
      Tyskie
      wrote on last edited by Tyskie
      #2

      Actually after thinking a bit I could even just put any class like my_app = MyCoreApp(args) add a QSystemTrayIcon() and my Qframe and just show those in there, right? I am not sure about the best practices tho. Because in that case the QFrame and Systray won't have a parent.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Tyskie
        wrote on last edited by
        #3

        Well it seems that QSystemTrayIcon cannot be a parent of a Qwidget

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          QMainWindow is "just" a widget like any other. Nothing makes its use mandatory in an application.

          Can you explain a bit more what you want to do with your QFrame object ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • T Offline
            T Offline
            Tyskie
            wrote on last edited by Tyskie
            #5

            Hi, thanks for your reply @SGaist,

            The QFrame are translucent containers, what I call the overlays. they hold some countdown widgets.
            see picture, I only need those Qframe and a Systray for the exit and setting window.
            But if I dont use MainWindow, I cannot 'link' it -as parent- to the systray and Qframe, making them difficult to interact together.

            Is having a MainWindow but not showing it just for 'convenience' is acceptable?

            0_1565994532833_def.png

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by SGaist
              #6

              Are these QFrames to be shown permanently or following a click on the QSystemTrayIcon ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • T Offline
                T Offline
                Tyskie
                wrote on last edited by Tyskie
                #7

                At least one is permanent, others can be added/removed, they are created dynamically based on a config file.
                For now I reverted to a QMainWindow that read the conf and create them, with the systray, its just not shown (no call to .show() ) and have the setQuitOnLastWindowClosed set to false, to avoid app close on setting window close.

                Edit: The systray is here only to close the app, and add settings to it (position of the overlay, size etc), there are no action possible (close, etc) on the overlay QFrame, The app is meant to run in background while overlays are shown - that's why I have concern about having a MainWindow that I dont really usr, but on the other hand I need something as a parent for all of those.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Did you took a look at the System Tray Icon Example ? It doesn't use any QMainWindow.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    Tyskie
                    wrote on last edited by
                    #9

                    Yes that is what I did earlier, But then its impossible to have parent for the QFrames and QDialog and interaction between both become hard

                    1 Reply Last reply
                    0
                    • hskoglundH Offline
                      hskoglundH Offline
                      hskoglund
                      wrote on last edited by
                      #10

                      Hi, have a similar type of systray icon app (text macro app, it translates for example the 3 keystrokes "brb" to "be right back" regardless if you're in Slack or Office365 etc.)
                      I also use a QMainWindow as the central "meeting" spot/class, but keeping it hidden for the lifetime of the app. Works fine.

                      1 Reply Last reply
                      0
                      • T Offline
                        T Offline
                        Tyskie
                        wrote on last edited by
                        #11

                        Thanks @hskoglund feeling good to not be alone, I guess I will keep going that way, just feel weird :D

                        1 Reply Last reply
                        0

                        • Login

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