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. Resizing and moving a QDockWidget when it is undocked
Qt 6.11 is out! See what's new in the release blog

Resizing and moving a QDockWidget when it is undocked

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 6.3k 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.
  • J Offline
    J Offline
    JulienMaille
    wrote on last edited by
    #1

    Hi folks, I have some QDockWidget that are sometimes docked in a big space but containing only small widgets.
    When undocking it I would like the QDockWidget to be resized to it's smallest size.
    I got this working by connecting the topLevelChanged signal. @connect(ui->statusDock, SIGNAL(topLevelChanged(bool)), this, SLOT(slotDockResized(bool)));

    void MainWindow::slotDockResized(bool b)
    {
    if( !b ) return;
    QDockWidget* senderDock = dynamic_cast<QDockWidget*>(QObject::sender());
    senderDock->adjustSize();
    senderDock->move(QCursor::pos().x()-0.5f*senderDock->width(), QCursor::pos().y()-10);
    }@ But unfortunately when the QDockWidget is dragged to be undocked and if the widget changes from something really large to something much smaller, there are chance that the QDockWidget won't be under the mouse cursor anymore (because during the resizing the upper left is the reference point).

    That's why I added the move() call. This works if the QDockWidget is undocked with a double click on its titlebar.
    But it won't work if it is undock with drag and drop. I guess that in that case the QDockWidget has already entered a mouseMove event and my own move() call is ignored.

    Any clue to bypass this?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      JulienMaille
      wrote on last edited by
      #2

      Is it possible to move a Widget that entered a drag event without reimplementing anything?

      1 Reply Last reply
      0
      • J Offline
        J Offline
        JulienMaille
        wrote on last edited by
        #3

        My very first BUMP here :p

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jim_kaiser
          wrote on last edited by
          #4

          Try if this works.. You can use negative values too in QWidget's geometry property.

          So instead of adjustSize().. you could use get the size using the senderDock->sizeHint() or senderDock->minimumSizeHint() and then do a senderDock->setGeometry(<The New Rect>) with a QRect of that size and centered on the current mouse cursor position relative to the widgets origin.

          1 Reply Last reply
          0
          • J Offline
            J Offline
            JulienMaille
            wrote on last edited by
            #5

            Thanks for your help. However I'm not sure I understood everything.
            As I said, the adjustSize() call works: the widget is correctly resized.
            The problem is with the move() call. Do you suggest me to replace it with a setGeometry()?

            1 Reply Last reply
            0

            • Login

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