Application with overlay and trayicon but no mainwindow
-
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_())
-
Actually after thinking a bit I could even just put any class like
my_app = MyCoreApp(args)
add aQSystemTrayIcon()
and myQframe
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. -
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 ?
-
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?
-
Are these QFrames to be shown permanently or following a click on the QSystemTrayIcon ?
-
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.
-
Did you took a look at the System Tray Icon Example ? It doesn't use any QMainWindow.
-
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. -
Thanks @hskoglund feeling good to not be alone, I guess I will keep going that way, just feel weird :D