PDA

View Full Version : A way to have QMainWindow dockage nicely ?



Alundra
16th March 2015, 21:45
Hi,
I tried long time ago to ask on this subject but without enough informations surely.
I have an application which create sub-window using QMainWindow but the problem is these windows are floating and not dockable.
Here a view of application which solved this problem :
Unreal Engine 4 (on the top) : http://zupimages.net/up/15/12/tqbk.png
Google Chrome (on the top) : http://img.clubic.com/03467126-photo-google-01.jpg
The goal is to have dockable window without waste a lot of space but still have the window undockable to have it on a second screen for example.
One important thing is the main dock window must not be closable only sub-windows has to be closable.
Is it possible in Qt ? What are steps needed to have that ?
Thanks for the help

Kryzon
17th March 2015, 01:14
Have you tried embedding a QMainWindow inside a QDockWidget?

Alundra
17th March 2015, 02:02
I had this idea too but the problem is you will have the tab bar which will takes space, on the unreal engine 4 and google chrome cases the space is not wasted.
One thing I didn't mention which can be make that perfect is to have ability to dock too in one floating window, on both example cases I showed you can do it.
I tried to undock two QDockWidget but it's not possible to dock one inside another on the default behavior of Qt.
Looks like when undock a new QMainWindow has to be created (only if undock from tab bar).

Kryzon
17th March 2015, 21:37
You understand that the docking system in Qt has a specific behaviour and set of features.
If you're not satisfied by adapting your software design to work like that system proposes, you'll have to modify that system at a source level, or implement an original docking system.

Qt offers absolutely all of the widget management you need to write your own custom docking system, but please consider how monumental a task it is. I've found two comments around the web -- one in these forums and the other at StackOverflow -- from developers that implemented their own original docking systems in their Qt-based software. Both remarked that it was an extremely challenging task, especially when animation is involved.
Note that these people were working in teams: they had resources like time, knowledge and funding. Because of that, both mentioned being under contracts that prevented them from publishing any code. This is why there's no progress regarding public solutions of custom docking systems for Qt: the developers capable of doing it are usually under contracts.

If I'm not mistaken you can embed a QMainWindow in a dock widget, and this works in your favour. A QMainWindow only accepts docks that were created by it, so you can have the following arrangement:
1) One application QMainWindow with top-area-only "scene" or "document" docks.
2) Each "document" dock has its own QMainWindow that you add a QGraphicsView and toolbox docks etc.
3) If you want more space for the "document" docks, you can try using something like this: detachable QDockWidget tabs (http://www.qtcentre.org/threads/61403-SOLVED-Detachable-QDockWidget-tabs)

I'd personally look into that, using the system already in Qt and making changes to my original software design, than implementing a whole new docking system.

Alundra
18th March 2015, 02:14
This is what I was afraid, Qt doesn't allow easily to make a google chrome style docking system.
I'm aware of the link you showed (http://www.qtcentre.org/threads/61403-SOLVED-Detachable-QDockWidget-tabs), It can be a good start for a custom system surely, you right.
The real problem in an application design to be good is to use the space efficiently, you surely know that and understand why I find the best solution.
This problem is the only real big problem I have using Qt and not easy to solve, it's a real advanced problem.
Maybe that's possible to use a custom titlebar on the QMainWindow and link the Qt dock behavior on it :
When the user dock, hide the titlebar of the dock and add a tab which is the current dock.
The custom QMainWindow has to use FramelessWindowHint.
At the end this is what the link you said do, only the tabbar could be customized to be google chrome style surely.
The only bad point is to have to reimplement resize because FramelessWindowHint remove it.

EDIT:
I found that : https://github.com/expobrain/tabbedwindow-qt
I compiled it, works fine, like google chrome behavior but :
- it doesn't have the close button on the dock but surely can be added easily
- if you dock on the same window it close the window, that's a bug
- if you close the main window it doesn't close the application

Alundra
18th March 2015, 16:07
You can see the wasted space on this screenshot :
http://zupimages.net/up/15/12/p4v9.png
No way to add a QWidget inside QMainWindow default titlebar ?

wysota
18th March 2015, 17:25
Chrome uses a custom title bar to show the tabs "in" the title bar. You can do the same for your application by removing the window frame completely and managing the window by yourself, just like Chrome does. X11 does not have an API to do this "natively".