Here follows an example project of how to achieve detachable (as in, click-drag to tear off) QDockWidget tabs, something which is quite standard in commercial software but somehow not implemented in Qt.
Qt does not support detachable dock widget tabs nor does it expose much of its docking system for us to implement it. However, by using some [stable] tricks and some research into the Qt source code we can achieve this behaviour. The inspiration for this was Toon Boom, a commercial software used for animation that was built with Qt, and it has detachable dock tabs. Some more sophisticated docking systems can be found in Adobe software such as Photoshop and Flash.
This thread (Dragable-QDockWidget-tabs-with-no-title-bar) makes an important point: "Displaying the title in the tab and the title bar seems ugly and a waste of screen space."
The original Qt docking system looks like this, as seen in Krita, a famous open-source digital painting application:
You can see highlighted in red that you have the name of the panel not only on the tab but also on the dock widget title bar, wasting vertical space.
This example project hides the title bars of dock widgets when they are tabified to compensate for that. Then it allows the user to detach the dock widget by dragging the tab or by double-clicking it.
It also implements the concept of a 'workspace,' which is nothing more than different QMainWindow states. A suggestion is to use this workspace system to allow the user to save their own custom dock arrangements.
Notes:
- For this system to work it's necessary to synthesize OS-level mouse events. This is platform specific, and in the attached example you will find the implementation for Windows (using the SendInput function). There's still the need to implement and test for OS X and Linux (X11). The system is stable nonetheless.
- This system works with graphics tablets (as in, you can detach and drag docks with the stylus). I tested it with a Wacom Bamboo graphics tablet and as such it can be used in software that supports this kind of input device.
- This is my first major C++ usage. If you have any recommendations for improvements in the code for clarity etc. please share your thoughts here or send me a PM. I will appreciate it. The source code is heavily commented with the C++ \ Qt novice in mind. This system can probably be ported to Python with ease.
Here's a screenshot of how it looks on my system, Windows XP:
If you have the time, please share a screenshot of how it looks on your system. The tab close button graphic is native, but it can probably be styled with a custom pixmap using the QTabBar::close-button CSS subcontrol.
References (these helped a lot):
- http://qt-project.org/faq/answer/how...ed_qdockwidget
- http://www.qtcentre.org/threads/1428...dget-is-docked
- http://www.qtcentre.org/wiki/index.p...e=Movable_Tabs
- http://blog.qt.digia.com/blog/2009/0...w-by-dragging/
Bookmarks