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?

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.
  • bibasmallB Offline
    bibasmallB Offline
    bibasmall
    wrote on 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?

    Christian EhrlicherC 1 Reply Last reply
    0
    • Christian EhrlicherC Christian Ehrlicher

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

      bibasmallB Offline
      bibasmallB Offline
      bibasmall
      wrote on 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
      • bibasmallB bibasmall

        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?

        Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 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

        bibasmallB 1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

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

          bibasmallB Offline
          bibasmallB Offline
          bibasmall
          wrote on 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.

          Christian EhrlicherC 1 Reply Last reply
          0
          • bibasmallB bibasmall

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

            Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 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

            bibasmallB 1 Reply Last reply
            1
            • Christian EhrlicherC Christian Ehrlicher

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

              bibasmallB Offline
              bibasmallB Offline
              bibasmall
              wrote on 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
              • bibasmallB bibasmall has marked this topic as solved on

              • Login

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