1

I create a dock widget in qt GUI and add a tree table widget on it. More than these in main menu I have others objects such QGraphicsView. In run time when I manually resize the dock's width, it pushes or pulls main window with it's objects and works good. when I resize dock in code, dock and it's objects overlap with main window's objects. how can I fix this? thank you for your attention.

in header file:

#include <QtWidgets/QMainWindow>
#include "ui_QtGuiApplication.h"
#include <QtWidgets/QDockWidget>
#include <QtWidgets/QTreeWidget>
#include <QGraphicsView>
#include <QtWidgets/QPushButton>

class QtGuiApplication : public QMainWindow
{
    Q_OBJECT

public:
    QtGuiApplication(QWidget *parent = Q_NULLPTR);


private:
    Ui::QtGuiApplicationClass ui;
    QDockWidget *dockWidget;
    QWidget *dockWidgetContents;
    QTreeWidget *treeWidget;
    QGraphicsView* qGraph;
    QGraphicsScene* scene;
private slots:
    void worker_fn();
};

in source file:

#include "QtGuiApplication.h"

QtGuiApplication::QtGuiApplication(QWidget *parent)
    : QMainWindow(parent)
{
    ui.setupUi(this);

    /// creat dock
    dockWidget = new QDockWidget(this);
    dockWidgetContents = new QWidget(); 
    dockWidget->setMinimumSize(QSize(50, 38));
    dockWidget->setWidget(dockWidgetContents);
    this->addDockWidget(static_cast<Qt::DockWidgetArea>(1), dockWidget);

    //// add tree table widget to dock
    treeWidget = new QTreeWidget(dockWidgetContents);

    //// creat an object in  main window
    qGraph = new QGraphicsView(ui.centralWidget);
    qGraph->setGeometry(QRect(70, 30, 300, 300));
    scene = new QGraphicsScene(qGraph);
    scene->setSceneRect(0, 0, 300, 300);
    qGraph->setScene(scene);
    qGraph->show();

    //////// creat push button to resize the dock
    QPushButton* btn_Ok = new QPushButton(ui.centralWidget);
    btn_Ok->setGeometry(QRect(340, 340, 75, 23));
    btn_Ok->setText("Ok");
    connect(btn_Ok, SIGNAL(clicked()), this, SLOT(worker_fn()));
}
void QtGuiApplication::worker_fn()
{
    QRect rect = dockWidget->geometry();
    dockWidget->resize(300, rect.height());
}
M.Hu
  • 121
  • 1
  • 14

0 Answers0