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. How to move QDockWidget when topLevelChanged?
Forum Update on Monday, May 27th 2025

How to move QDockWidget when topLevelChanged?

Scheduled Pinned Locked Moved Solved General and Desktop
qdockwidgetmulti-screenmove problemsetgeometryqt6
5 Posts 2 Posters 778 Views
  • 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.
  • B Offline
    B Offline
    bibasmall
    wrote on 22 May 2023, 11:19 last edited by bibasmall
    #1

    Hello everyone!

    My problem is that when I drag QDockWidget, it always appears floating on the primary screen, regardless of where my main window is. This behavior is observed even in an empty Qt project (Qt 6.3.2, Windows 10) with QMainWindow and QDockWidget's only, so the only thing I can do here is to move QDockWidget somehow when QDockWidget::topLevelChanged is emitted .
    But nothing helps with moving it. Here is what I've tried, of course not at the same time:

    CDockWidget::CDockWidget() : QDockWidget()
    {
            setScreen->(QGuiApplication::screens()[1]); //no effect
    
    	connect(this, &QDockWidget::topLevelChanged, [this](bool) {
    
    		auto screen = QGuiApplication::screenAt(QCursor::pos());
    		auto geom = screen->availableGeometry();
    		QPoint pos = { (geom.width() - width()) / 2, (geom.height() - height()) / 2 };
    		QRect dockGeom = { pos, size() };
    		setGeometry(dockGeom); //no effect
    		
                    move(pos); //no effect
    		
                    move(-50000, -50000); //no effect
                    
                    setGeometry(0, 0, 500, 500); //dock widget appears floating on the same place and has size 500, 500
    
    		hide();
    		move(pos);
    		show(); //no effect
    		
    		setScreen->(QGuiApplication::screens()[1]); //no effect
    	});
    }
    

    Any ideas how can I achieve my goal?

    C 1 Reply Last reply 22 May 2023, 11:51
    0
    • C Christian Ehrlicher
      22 May 2023, 12:46

      The patch is trivial - so when you already compile Qt by yourself you can apply it.

      B Offline
      B Offline
      bibasmall
      wrote on 22 May 2023, 16:45 last edited by
      #5

      @Christian-Ehrlicher
      Thank you, it helped!
      In fact, these two commits contained what I needed:
      Fix dragging a docked QDockWidget [REG-fix]
      430985: Refix QDockwidget drag out dockwidget

      1 Reply Last reply
      1
      • B bibasmall
        22 May 2023, 11:19

        Hello everyone!

        My problem is that when I drag QDockWidget, it always appears floating on the primary screen, regardless of where my main window is. This behavior is observed even in an empty Qt project (Qt 6.3.2, Windows 10) with QMainWindow and QDockWidget's only, so the only thing I can do here is to move QDockWidget somehow when QDockWidget::topLevelChanged is emitted .
        But nothing helps with moving it. Here is what I've tried, of course not at the same time:

        CDockWidget::CDockWidget() : QDockWidget()
        {
                setScreen->(QGuiApplication::screens()[1]); //no effect
        
        	connect(this, &QDockWidget::topLevelChanged, [this](bool) {
        
        		auto screen = QGuiApplication::screenAt(QCursor::pos());
        		auto geom = screen->availableGeometry();
        		QPoint pos = { (geom.width() - width()) / 2, (geom.height() - height()) / 2 };
        		QRect dockGeom = { pos, size() };
        		setGeometry(dockGeom); //no effect
        		
                        move(pos); //no effect
        		
                        move(-50000, -50000); //no effect
                        
                        setGeometry(0, 0, 500, 500); //dock widget appears floating on the same place and has size 500, 500
        
        		hide();
        		move(pos);
        		show(); //no effect
        		
        		setScreen->(QGuiApplication::screens()[1]); //no effect
        	});
        }
        

        Any ideas how can I achieve my goal?

        C Online
        C Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 22 May 2023, 11:51 last edited by
        #2

        @bibasmall said in How to move QDockWidget when topLevelChanged?:

        Any ideas how can I achieve my goal?

        Try with Qt 6.5. If the problem still occous see if there is a bug report about it already and if not create one.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        B 1 Reply Last reply 22 May 2023, 12:10
        0
        • C Christian Ehrlicher
          22 May 2023, 11:51

          @bibasmall said in How to move QDockWidget when topLevelChanged?:

          Any ideas how can I achieve my goal?

          Try with Qt 6.5. If the problem still occous see if there is a bug report about it already and if not create one.

          B Offline
          B Offline
          bibasmall
          wrote on 22 May 2023, 12:10 last edited by bibasmall
          #3

          @Christian-Ehrlicher
          I've found it here:
          QTBUG-106064[REG] Undocking QDockWidget with drag misplaces it (a lot)
          Sadly I can't use fresher versions because of the second target platform, so it seems I should checkout 6.2.7.
          But I would be fine with additional manipulations that can move the widget, because these two actions (undocking and moving) don't look connected.

          C 1 Reply Last reply 22 May 2023, 12:46
          0
          • B bibasmall
            22 May 2023, 12:10

            @Christian-Ehrlicher
            I've found it here:
            QTBUG-106064[REG] Undocking QDockWidget with drag misplaces it (a lot)
            Sadly I can't use fresher versions because of the second target platform, so it seems I should checkout 6.2.7.
            But I would be fine with additional manipulations that can move the widget, because these two actions (undocking and moving) don't look connected.

            C Online
            C Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 22 May 2023, 12:46 last edited by
            #4

            The patch is trivial - so when you already compile Qt by yourself you can apply it.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            B 1 Reply Last reply 22 May 2023, 16:45
            1
            • C Christian Ehrlicher
              22 May 2023, 12:46

              The patch is trivial - so when you already compile Qt by yourself you can apply it.

              B Offline
              B Offline
              bibasmall
              wrote on 22 May 2023, 16:45 last edited by
              #5

              @Christian-Ehrlicher
              Thank you, it helped!
              In fact, these two commits contained what I needed:
              Fix dragging a docked QDockWidget [REG-fix]
              430985: Refix QDockwidget drag out dockwidget

              1 Reply Last reply
              1
              • B bibasmall has marked this topic as solved on 22 May 2023, 16:45

              1/5

              22 May 2023, 11:19

              • Login

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