[Qt-interest] widget in dockwidget do not get resized

Yifei Li yifli at mtu.edu
Thu Nov 3 22:10:00 CET 2011


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->addDockWidget(Qt::LeftDockWidgetArea, dock);

    }
};

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
}

On Nov 3, 2011, at 4:34 PM, Andreas Pakulat wrote:

> On 03.11.11 16:11:39, Yifei Li wrote:
>> 
>> 
>> On Nov 3, 2011, at 2:52 PM, Andre Somers wrote:
>> 
>>> Op 3-11-2011 19:29, Yifei Li schreef:
>>>> Hi all,
>>>> 
>>>> I did two experiments:
>>>> 
>>>> 1) add a QTextEdit directly to a QDockWidget, and the QTexEdit gets resized whenever its containing dock widget is resized
>>>> 
>>>> 2) However, if I put a QTextEdit in a layout which is set to be the layout of some other  QWidget W, and then add the QWidget W to the dock widget, the widget W is not resized when I resize the dockwidget
>>>> 
>>>> What should I do to make the widget W's change its size when the dock widget is resized?
>>>> 
>>> Make sure that widget W is in a layout itself,
>> You can't set a layout for a QDockWidget, although setLayout method exists for QDockWidget.
>> I have tried this, 
>> 1) set a layout for QDockWidget
>> 2) add widgets to the layout
>> 3) NOTHING shows up in the QDockWidget
>> 
>> I don't understand why.
> 
> Then create a small self-contained compilable example showing the
> problem.  Either you'll discover your error while doing so or someone
> here will likely be able to point it out.
> 
> 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