Qt-interest Archive, July 2007
Can I change the size of a DockWidget?
Message 1 in thread
Hi,
I'd like to lay out dock widgets like they are regular widgets while
they are docked. I've tried putting the dock widget into my layout, and
this works just fine. When I make the dock widget go toplevel, that
works too. The only problem that I have is that the toplevel dock widget
cannot be moved around by dragging the title bar.
Is it a boneheaded move to stick a dock widget into a layout?
Thanks,
Patrick
--
[ signature omitted ]
Message 2 in thread
On 02.07.07 17:55:40, Patrick Draper wrote:
> I'd like to lay out dock widgets like they are regular widgets while they are
> docked. I've tried putting the dock widget into my layout, and this works just
> fine. When I make the dock widget go toplevel, that works too. The only problem
> that I have is that the toplevel dock widget cannot be moved around by dragging
> the title bar.
>
> Is it a boneheaded move to stick a dock widget into a layout?
IMHO: yes. Reason: Well you obviously don't need anything from the
dockwidget, except the possibility to make it a top-level widget. Unless
I'm mistaken you can easily achieve with a toolbutton and a
setParent(0) call and vice-versa to dock it again.
Andreas
--
[ signature omitted ]
Message 3 in thread
Andreas Pakulat wrote:
>
> IMHO: yes. Reason: Well you obviously don't need anything from the
> dockwidget, except the possibility to make it a top-level widget. Unless
> I'm mistaken you can easily achieve with a toolbutton and a
> setParent(0) call and vice-versa to dock it again.
>
I'm not really following why it is obvious that I don't need anything
from a dock widget. I'm essentially trying to duplicate what the
assistant does with its dock widget. The problem I have is that the size
of the dock widget is too small. I would be happy if the dock widget
would just display the entire Tree View.
I do absolutely need to be able to dock this on the top, bottom, left,
or right. I want the dock widget to show the whole tree view inside the
dock widget. I have 4 columns on the right that aren't displayed when
the dock widget is docked!
I must be missing something obvious, or I'm not communicating this very
well.
Thanks, Patrick.
--
[ signature omitted ]
Message 4 in thread
On 02.07.07 18:44:21, Patrick Draper wrote:
> Andreas Pakulat wrote:
> >
> >IMHO: yes. Reason: Well you obviously don't need anything from the
> >dockwidget, except the possibility to make it a top-level widget. Unless
> >I'm mistaken you can easily achieve with a toolbutton and a
> >setParent(0) call and vice-versa to dock it again.
> >
>
> I'm not really following why it is obvious that I don't need anything
> >from a dock widget. I'm essentially trying to duplicate what the
> assistant does with its dock widget. The problem I have is that the size of the
> dock widget is too small. I would be happy if the dock widget would just
> display the entire Tree View.
>
> I do absolutely need to be able to dock this on the top, bottom, left, or
> right. I want the dock widget to show the whole tree view inside the dock
> widget. I have 4 columns on the right that aren't displayed when the dock
> widget is docked!
Sorry, but I think I'm missing something. Qt assistant doesn't add the
dockwidget to any layout, it just has a standard dockwidget. It also
doesn't do any resizing of the dockwidget when the content of one of the
tabs is too wide. If you want that you should look for signals that are
emitted when the tree changes and then use the width of the columns to
set a new size on the dockwidget. Not sure this works, though.
Anyway, stuffing a QDockWidget into a layout of a widget is still
not a good idea.
Andreas
--
[ signature omitted ]
Message 5 in thread
Andreas Pakulat wrote:
> Sorry, but I think I'm missing something. Qt assistant doesn't add the
> dockwidget to any layout, it just has a standard dockwidget. It also
I added the dock widget to the layout as an experiment to see if I could
get it to resize while it was docked. I could, although I now see that's
not a correct usage of the widget.
> doesn't do any resizing of the dockwidget when the content of one of the
> tabs is too wide. If you want that you should look for signals that are
> emitted when the tree changes and then use the width of the columns to
> set a new size on the dockwidget. Not sure this works, though.
I've called resize() directly on the dockwidget. It resizes when it is
floating, but not when it's docked. I'm going to dig into the assistant
application to see how the size is changed there. The dock widget is
perfectly sized to fit 4 tabs on that application. That dock widget is
also a different size than what I'm seeing on my app.
Thanks, Patrick
--
[ signature omitted ]
Message 6 in thread
On 02.07.07 22:09:04, Patrick Draper wrote:
> Andreas Pakulat wrote:
> >doesn't do any resizing of the dockwidget when the content of one of the
> >tabs is too wide. If you want that you should look for signals that are
> >emitted when the tree changes and then use the width of the columns to
> >set a new size on the dockwidget. Not sure this works, though.
>
> I've called resize() directly on the dockwidget. It resizes when it is
> floating, but not when it's docked. I'm going to dig into the assistant
> application to see how the size is changed there. The dock widget is perfectly
> sized to fit 4 tabs on that application. That dock widget is also a different
> size than what I'm seeing on my app.
But assistant doesn't resize its dockwidget, it doesn't do anything
special to it (as far as I can see from a user pov).
Andreas
--
[ signature omitted ]
Message 7 in thread
Andreas Pakulat wrote:
> But assistant doesn't resize its dockwidget, it doesn't do anything
> special to it (as far as I can see from a user pov).
>
> Andreas
To see how assistant resizes its dockwidget, open assistant, move the
slider to make the dock widget very large, close the assistant, reopen
the assistant, and you'll see that it's saved the size of the dock
widget and restored it for you. That behavior indicated to me that the
size of the dock widget could be under program control. That was good,
because the Dock Widget I was seeing was very narrow. Hardly big enough
to hold a single pushbutton.
I checked the Qt source code and the dock widget has a custom layout
class called QDockWidgetLayout in the file gui/dockwidgetlayout.cpp
which appears to do some layout on the widget contained inside the dock
widget. So, when I was calling resize() on the widget contained it
wasn't changing the size. Since the contained widget is in a layout, I
needed to change the maximum and minimum sizes so the QDockWidgetLayout
would understand how big the widget needed to be. I used the
setFixedWidth function on QWidget to make sure that both the maximum and
minimum were set properly.
That solved the problem. Before, the Dock Widget Layout was very very
narrow. It always required the user to move the slider so the tree could
be visible. Now I can calculate the maximum allowable area in the window
that the dock widget can occupy, and make it occupy that area.
The clue that I received was from examination of the source code to the
Qt Assistant application. There is a call in there to
QWidget::restoreGeometry on the helpDock object (the widget contained in
Assistant's dock widget). That in turn calls QWidget::resize() which is
restrained by the minimum and maximum sizes of the widget. So, I
reasoned that setting the minimum and maximum sizes of the contained
widget would solve the problem and it did.
Patrick
--
[ signature omitted ]
Message 8 in thread
On 03.07.07 10:12:52, Patrick Draper wrote:
> Andreas Pakulat wrote:
> >But assistant doesn't resize its dockwidget, it doesn't do anything
> >special to it (as far as I can see from a user pov).
> >
> >Andreas
> To see how assistant resizes its dockwidget, open assistant, move the slider to
> make the dock widget very large, close the assistant, reopen the assistant, and
> you'll see that it's saved the size of the dock widget and restored it for you.
Uhm, but thats Qt built-in stuff. I'm currently not sure how to do that
code-wise but IIRC there are functions in QMainWindow to store the
dockwindow settings.
> That behavior indicated to me that the size of the dock widget could be under
> program control. That was good, because the Dock Widget I was seeing was very
> narrow. Hardly big enough to hold a single pushbutton.
Hasn't happened to me, I may be mistaken here, but I think the
dockwidgets width depends on the expansion settings of the central
widget and the size of the mainwindow.
Andreas
--
[ signature omitted ]
Message 9 in thread
Andreas Pakulat wrote:
>> To see how assistant resizes its dockwidget, open assistant, move the slider to
>> make the dock widget very large, close the assistant, reopen the assistant, and
>> you'll see that it's saved the size of the dock widget and restored it for you.
>>
>
> Uhm, but thats Qt built-in stuff. I'm currently not sure how to do that
> code-wise but IIRC there are functions in QMainWindow to store the
> dockwindow settings.
>
The functions are saveGeometry and restoreGeometry. They call resize (),
but resize() is constrained by the minimum and maximum widget width.
>> That behavior indicated to me that the size of the dock widget could be under
>> program control. That was good, because the Dock Widget I was seeing was very
>> narrow. Hardly big enough to hold a single pushbutton.
>>
>
> Hasn't happened to me, I may be mistaken here, but I think the
> dockwidgets width depends on the expansion settings of the central
> widget and the size of the mainwindow.
>
Yes, it depends on the central widget, but not the mainwindow size. Even
when my mainwindow was 1500 pixels wide the dock widget was 50 pixels
wide. I couldn't find a relationship to the mainwindow size. Only the
central widget size. In my case the maximum width was being set too
narrow by default.
Patrick
--
[ signature omitted ]
Message 10 in thread
Andreas Pakulat wrote:
> Anyway, stuffing a QDockWidget into a layout of a widget is still
> not a good idea.
After more experimenting, I realized that the sizes that I was setting
on the widgets contained inside of the Dock Widget were being subjected
to a layout manager and being overridden.
I solved my problem using the setFixedWidth() function. My other widgets
on the screen are always the same width - fixed formatted text display -
so it's a simple matter to calculate the leftover space to size the
widget inside of the dock.
Thanks for your help,
Patrick
--
[ signature omitted ]