[Qt-interest] widget in dockwidget do not get resized
Yifei Li
yifli at mtu.edu
Fri Nov 4 00:36:17 CET 2011
On Nov 3, 2011, at 6:52 PM, Andreas Pakulat wrote:
> On 03.11.11 17:10:00, Yifei Li wrote:
>>
>> The following is a minimal example that shows my problem. TreeWidget does not show up in the dock widget.
>>
>> #include <QtGui/QApplication>
>> #include <QMainWindow>
>> #include <QDockWidget>
>> #include <QVBoxLayout>
>> #include <QTreeWidget>
>> #include <QTextEdit>
>>
>> class MainWindow : public QMainWindow {
>> public:
>> MainWindow(QWidget* parent = 0)
>> :QMainWindow(parent)
>> {
>> QTextEdit* edit = new QTextEdit();
>> this->setCentralWidget(edit);
>> QDockWidget * dock = new QDockWidget(this);
>> QVBoxLayout* layout = new QVBoxLayout();
>> QTreeWidget* tree = new QTreeWidget();
>> layout->addWidget(tree);
>> dock->setLayout(layout);
>
> This is your problem. You're not supposed to set a layout on a
> dockwidget since QDockWidget will have its own layout (probably set when
> using addDockWidget, but didn't find the place right away in the
> sources). This is so it can have a maximize/minimize button etc. when
> necessary. Thats the same situation as QMainWindow and its central
> widget, so simply use the setWidget function and supply an intermediate
> QWidget on which you set the layout:
>
> QWidget* tmpwidget = new QWidget();
> tmpwidget->setLayout(layout);
> dock->setwidget(tmpwidget);
I was wrong. This approach is correct. The reason it did not work was due to some other problem in my application.
Thank you for your help
>
> You should also have gotten a warning on stderr (or Windows debug
> channel) when running your example that a layout is being set on
> QDockWidget while it already has one. This also hints at the fact that
> Qt internally sets a layout on the dockwidget when adding it to a
> mainwindow.
>
> Andreas
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list