Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

The content of MainWindow which is on a desktop couldn't be resized when a DockWidget which is on another desktop is maximized.



  • I am working on Qt 5.12 MSVC64 and create a MainWindow with two DockWidget.

    The window flags of the DockWidgets are modified to show maximize and minimize buttons.

    The header file is as below

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    #include <QDockWidget>
    #include <QCloseEvent>
    #include <QLabel>
    
    namespace Ui {
    class MainWindow;
    }
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        explicit MainWindow(QWidget *parent = nullptr);
        ~MainWindow();
    
    private:
        Ui::MainWindow *ui;
    
        void Init_UI();
    
    private slots:
        void slot_dockWidget_topLevelChanged();
    };
    
    #endif // MAINWINDOW_H
    

    The source file is as below

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        Init_UI();
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    void MainWindow::Init_UI(){
        // init status bar
        QLabel *pLabel = new QLabel(this);
        pLabel->setText("Status Bar");
        ui->statusBar->addPermanentWidget(pLabel, 0);
    
        // set center widget
        this->centralWidget()->setMaximumSize(1, 0);
    
        // set dockwidget 1
        ui->dockWidget->setWindowTitle("1");
        connect(ui->dockWidget, SIGNAL(topLevelChanged(bool)), this, SLOT(slot_dockWidget_topLevelChanged()));
        addDockWidget(Qt::LeftDockWidgetArea, ui->dockWidget);
    
        // set dockwidget 2
        ui->dockWidget_2->setWindowTitle("2");
        connect(ui->dockWidget_2, SIGNAL(topLevelChanged(bool)), this, SLOT(slot_dockWidget_topLevelChanged()));
        addDockWidget(Qt::RightDockWidgetArea, ui->dockWidget_2);
    }
    
    void MainWindow::slot_dockWidget_topLevelChanged(){
        QDockWidget* pDock_Widget = static_cast<QDockWidget*>(QObject::sender());
        if(pDock_Widget->isFloating()){
            pDock_Widget->setWindowFlags(Qt::CustomizeWindowHint |
                                         Qt::Window |
                                         Qt::WindowCloseButtonHint |
                                         Qt::WindowMinimizeButtonHint |
                                         Qt::WindowMaximizeButtonHint
                                         );
            pDock_Widget->show();
        }
    }
    

    The resize issue will happen as following procedure.

    Step1. Run MainWindow and put it on first desktop
    The picture of Step1

    Step2. Drag DockWidget_2 into second desktop
    The picture of Step2

    Step3. Press the maximize button of DockWidget_2
    The picture of Step3

    Step4. Resize the MainWindow
    The picture of Step4

    The DockWidget_1, menu bar and status bar aren't resized.

    Thanks for any suggestions.



  • Can you try replacing QDockWidget with those that come from this library and see if it fixes the problem? https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System

    P.S.
    Great Avatar!



  • Can you try replacing QDockWidget with those that come from this library and see if it fixes the problem? https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System

    P.S.
    Great Avatar!



  • @g69310026

    Looks like your central widget in your MainWindow has no layout.

    @g69310026 said in The content of MainWindow which is on a desktop couldn't be resized when a DockWidget which is on another desktop is maximized.:

    this->centralWidget()->setMaximumSize(1, 0);

    What's the purpose of this line?

    @VRonin said in The content of MainWindow which is on a desktop couldn't be resized when a DockWidget which is on another desktop is maximized.:

    Great Avatar!

    Memories... The good old days....*sigh* :-)



  • @VRonin

    Thanks for your reply.

    I will try it and feedback the testing result.

    ps

    Fatail1ty is my favorite player.



  • @Pl45m4

    I want that only dockwidgets are inside the main window.

    So I set the height of the central widget to 1 for “hiding” it.



  • Sorry for the late reply.

    I tested the Advanced Docking System and there is no the same issue.

    The header file is as below

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    #include <QDockWidget>
    #include <QCloseEvent>
    #include <QLabel>
    
    #include "DockManager.h"
    
    namespace Ui {
    class MainWindow;
    }
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        explicit MainWindow(QWidget *parent = nullptr);
        ~MainWindow();
    
    private:
        Ui::MainWindow *ui;
    
        ads::CDockManager* m_DockManager;
    
        void Init_UI();
        void Init_ADS();
    
    private slots:
        void slot_dockWidget_topLevelChanged();
    };
    
    #endif // MAINWINDOW_H
    

    The source file is as below

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        Init_UI();
        Init_ADS();
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    void MainWindow::Init_UI(){
        // init status bar
        QLabel *pLabel = new QLabel(this);
        pLabel->setText("Status Bar");
        ui->statusBar->addPermanentWidget(pLabel, 0);
    
        // set center widget
        this->centralWidget()->setMaximumSize(100, 0);
    
        // set dockwidget 1
        ui->dockWidget->setWindowTitle("1");
        connect(ui->dockWidget, SIGNAL(topLevelChanged(bool)), this, SLOT(slot_dockWidget_topLevelChanged()));
        addDockWidget(Qt::LeftDockWidgetArea, ui->dockWidget);
        ui->dockWidget->hide();
    
        // set dockwidget 2
        ui->dockWidget_2->setWindowTitle("2");
        connect(ui->dockWidget_2, SIGNAL(topLevelChanged(bool)), this, SLOT(slot_dockWidget_topLevelChanged()));
        addDockWidget(Qt::RightDockWidgetArea, ui->dockWidget_2);
        ui->dockWidget_2->hide();
    }
    
    void MainWindow::Init_ADS(){
        // set dockwidget 1
        m_DockManager = new ads::CDockManager(this);
    
        QLabel* l = new QLabel();
        l->setText("Lorem ipsum dolor sit amet, consectetuer adipiscing elit.");
    
        ads::CDockWidget* DockWidget = new ads::CDockWidget("ADS_DockWidget 1");
        DockWidget->setWidget(l);
    
        ui->menuBar->addAction(DockWidget->toggleViewAction());
        m_DockManager->addDockWidget(ads::TopDockWidgetArea, DockWidget);
    
        // set dockwidget 2
        QLabel* l_2 = new QLabel();
        l_2->setText("Lorem ipsum dolor sit amet, consectetuer adipiscing elit.");
    
        ads::CDockWidget* DockWidget_2 = new ads::CDockWidget("ADS_DockWidget 2");
        DockWidget_2->setWidget(l_2);
    
        ui->menuBar->addAction(DockWidget_2->toggleViewAction());
        m_DockManager->addDockWidget(ads::TopDockWidgetArea, DockWidget_2);
    }
    
    void MainWindow::slot_dockWidget_topLevelChanged(){
        QDockWidget* pDock_Widget = static_cast<QDockWidget*>(QObject::sender());
        if(pDock_Widget->isFloating()){
            pDock_Widget->setWindowFlags(Qt::CustomizeWindowHint |
                                         Qt::Window |
                                         Qt::WindowCloseButtonHint |
                                         Qt::WindowMinimizeButtonHint |
                                         Qt::WindowMaximizeButtonHint
                                         );
            pDock_Widget->show();
        }
    }
    


  • I found a workaround solution.

    1.Reimplement QDockWidget class

    2.When the dockWidget got Qt::WindowMaximized or Qt::WindowNotState event, send Event::NonClientAreaMouseMove to the dockWidget.

    The issue will be fixed.


Log in to reply