Modern titlebars in Qt widget based desktop applications
-
Is it possible to have modern looking titlebars, that allow the app to place widgets inside them, in a Qt widget based desktop application. For eg - In the following apps (macOS and win), the content extends into the title bar
I would like to avoid creating a frameless window and writing my own custom titlebar.
-
Hi,
Since these are provided by the OS, you will need to add platform specific code to modify the title bar.
-
@SGaist Do you have any suggestions on how to approach the problem?
The easiest solution would be to make the QMainWindow frameless and draw the titlebar myself. However, that is not ideal since it removes the chrome as well and leads to a poor user experience. For eg - Window borders, shadows are lost, traffic lights (and equiavalent controls on win) are lost, resize/move have to be handled manually and operations provided by the window manager (snap to side etc) also stop working. It seems Qt is aware of these issues as per this blog post https://docs.microsoft.com/en-us/windows/win32/dwm/customframe#extending-the-client-frame
I would like to keep as much native look and feel and functionality of the titlebars/window manager as possible.
One approach would be to create a native window myself using the OS APIs and make the content extend into the title bar. Then somehow embed a QWidget in the root view of the window. However, I am not sure if this would be possible and/or a robust solution.
-
You can get a native window from Qt.
Based on the link you posted, there's an native event loop handler that you would need to implement in order to manage the native events of interest.
-
Sorry, I shared the incorrect blog post, I wanted to share this instead https://www.qt.io/blog/custom-window-decorations, though it doesn't solve much.