How to add additional controls to window title bar
-
@rock-wang
this is only possible if you draw the frame yourself.
For that you need to set the window flags to a frameless window and handle the resizing and moving of the window yourself.
In your custom title bar element you then can place any elements your like. -
@raven-worx How to handle resizeing and moving myself? Do you have some examples?
-
@rock-wang
Read this little article about how to implement the move and resize events inside of QML:
https://evileg.com/en/post/280/You can do many things with QML
-
With Qt 5.15 a new feature was added to aid in the handling of resize and move logic in this situation where you set your window with the
Qt.FramelessWindowHint
flag.
Now you can instruct the window manager to start a system resize or move on the window, instead of implementing the logic yourself: -
I think on Windows starting with Win10 or 11 you can add a compositor flag and windows will do this for you.
https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/nf-dwmapi-dwmsetwindowattribute
Also way back when all the cool kids on Win32 were doing custom clipping regions with the HDCs in order to create windows with custom regions or whatever for creating odd window shapes.
-
Have you consider whether you should do this?
The title bar has a consistent function that users expect on the platform, one of them being able to double click on it to go full screen, click and hold to drag etc.
Adding custom widgets will simply make it harder to use and your users will hate you for your bad UX when they miss click on some silly widget accidentally.
I'd suggest you put your widgets in the status bar which is typically at the bottom of the main window. This use case is also already well covered by Qt and is simple to do.