Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. The content of MainWindow which is on a desktop couldn't be resized when a DockWidget which is on another desktop is maximized.
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 454 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • g69310026G Offline
    g69310026G Offline
    g69310026
    wrote on last edited by g69310026
    #1

    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.

    Pl45m4P 1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      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!

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      g69310026G 1 Reply Last reply
      0
      • g69310026G g69310026

        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.

        Pl45m4P Offline
        Pl45m4P Offline
        Pl45m4
        wrote on last edited by Pl45m4
        #3

        @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* :-)


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        g69310026G 1 Reply Last reply
        0
        • VRoninV VRonin

          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!

          g69310026G Offline
          g69310026G Offline
          g69310026
          wrote on last edited by
          #4

          @VRonin

          Thanks for your reply.

          I will try it and feedback the testing result.

          ps

          Fatail1ty is my favorite player.

          1 Reply Last reply
          0
          • Pl45m4P Pl45m4

            @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* :-)

            g69310026G Offline
            g69310026G Offline
            g69310026
            wrote on last edited by
            #5

            @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.

            1 Reply Last reply
            0
            • g69310026G Offline
              g69310026G Offline
              g69310026
              wrote on last edited by
              #6

              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();
                  }
              }
              
              1 Reply Last reply
              0
              • g69310026G Offline
                g69310026G Offline
                g69310026
                wrote on last edited by g69310026
                #7

                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.

                1 Reply Last reply
                2

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved