PDA

View Full Version : QDockWidget problems



Kryzon
28th December 2014, 01:25
Hello.
I have a couple of problems with QDockWidgets.

1) Using a UI designed with Qt Designer, in my test program I can't resize a particular docked dockwidget beyond a certain amount, like I have reached its "minimum width" value.
The dock widget is empty, it has no content. When I change the "minimum width" value to something like 10px through Designer and manually resize the dock widget, it is still bound by a minimum value which is 79px -- the dock widget is still limited by this arbitrary value despite having no content.
How can I set a minimum width \ height for my dock widgets and have they respect this?


2) I'd like to have a 'dynamic layout' in a dock widget. I designed it vertically like the following, and I'd like for the content to be arranged horizontally when it's docked at the top or bottom of the main window:

http://s23.postimg.org/5z6gag361/QDockwidget_layout.png

Those "cells" are tool buttons, so this dock widget looks like a tool bar -- I don't want to use an actual tool bar because a tool bar has limited dock areas and is always at the edge of the main window, whereas a dock widget can be nested and tabbed with the other dock widgets in many more interesting ways.
The layouts offered in Designer seem to only allow one fixed direction at a time, so if I relocate that vertical dock widget to the top or bottom areas, the tool buttons are still vertical instead of being arranged horizontally.
Is there a layout that changes depending on the area that the dock widget is docked? It's especially important that this layout works with that "blue preview" region that is displayed when you're about to drop a dock widget on a new area. If this layout change is done manually through code, the blue preview region would not reflect the end result of the dock widget, as far as I know, as it would show the preview of dropping the dock widget with the old layout instead of the new layout that is enacted manually by code.

Added after 1 7 minutes:

After some more experimentation, regarding #1, the arbitrary size seems to be imposed by the dock widget title bar.

If I try to resize a dock widget to make the title bar have less than 79px width, it stops. Is there a way to remove this constraint?

d_stranz
28th December 2014, 16:23
According to the docs for QDockWidget:



Appearance

A QDockWidget consists of a title bar and the content area. The title bar displays the dock widgets window title, a float button and a close button. Depending on the state of the QDockWidget, the float and close buttons may be either disabled or not shown at all.

The visual appearance of the title bar and buttons is dependent on the style in use.


So if you want to turn those off (in which case your dock widget will probably cease to be movable or dockable because the title bar is what enables that), you're going to have to mess with the style settings (in QStyleOptionDockWidget or the style sheet). The buttons need a minimum width in order to remain visible.

Probably your best solution for the orientation problem is to design two layouts for the widget contents, one for vertical orientation and one for horizontal orientation. When you receive the dockLocationChanged() signal, you show the appropriate layout and hide the other.

ChrisW67
28th December 2014, 18:41
The stop as you resize the dockwidgets down is probably the behaviour of the splitter that is inserted by the QMainWindow. I suspect that QSplitter::childrenCollapsible() is false and stops at the largest dockwidget's size hint or some arbitrary minumum. If you can get a pointer to the splitter you might be able to check that.

Kryzon
29th December 2014, 10:45
I want to preserve the title bar. I just wish that the dock widget would reduce further than those 79px, even when empty.


Probably your best solution for the orientation problem is to design two layouts for the widget contents, one for vertical orientation and one for horizontal orientation. When you receive the dockLocationChanged() signal, you show the appropriate layout and hide the other.
That does work technically, but unfortunately the blue frame that shows a preview of the docked widget will show an innacurate size. When the layouts are switched the preview and the result will look different.


The stop as you resize the dockwidgets down is probably the behaviour of the splitter that is inserted by the QMainWindow. I suspect that QSplitter::childrenCollapsible() is false and stops at the largest dockwidget's size hint or some arbitrary minumum. If you can get a pointer to the splitter you might be able to check that.
The same happens if I float the dock widget and work on it alone, leaving the main window aside.
When scaling a vertical dock widget in the horizontal dimension, it will stop at 79px width instead of reducing all the way to zero, for example, in case of an empty dock widget.
It seems to be an arbitrary value, as even the title of the widget will be cut out and the end replaced with an ellipsis like so: "longWidgetTitl..."

I'll try reporting this as a bug.
(EDIT) Here's the report for reference: https://bugreports.qt-project.org/browse/QTBUG-43579