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. QDockWidget: difference between move() and mouse drag
Forum Updated to NodeBB v4.3 + New Features

QDockWidget: difference between move() and mouse drag

Scheduled Pinned Locked Moved General and Desktop
9 Posts 2 Posters 4.2k 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.
  • M Offline
    M Offline
    MrRipple
    wrote on last edited by
    #1

    Hi all,
    i need to grab/move/release a floating QDockWidget in a dockable area of my main window.
    I have implemented the function MyMainWindow::mousePressEvent and MyMainWindow::mouseMoveEvent.
    In MyMainWindow::mouseMoveEvent i call myDockWidget->move(pos)... but in this way I can move myDockWidget but it's not dockable!
    Why?

    What i do is:

    1. In MyMainWindow::mousePressEvent():
      I get a pointer of a QListWidgetItem. The QListWidget is in a QDockWidget in LeftDockArea.

    2. In MyMainWindow::mouseMoveEvent():
      According to the text of QListWidgetItem pointer, I create a new floating QDockWidget (movable, flotable and dockable to the right area).

    What I would do is:
    3) To move the new floating QDockWidget to attach it in the right dock area without to release mouse button (so during a mouseMoveEvent).

    If I use the QDockWidget::move(QCursor:: pos()) method I can move the new floating QDockWidget but it's not dockable and if I want dock the new QDockWidget I need to release mouse button and to do a click button on QDockWidget title bar... so i can move it and it's dockable.

    Any Idea?
    Can you help me?
    Tnx.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MrRipple
      wrote on last edited by
      #2

      No one knows how to do or can not do?

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi and welcome to devnet,

        There's something not clear about what you are asking, do you want to programmatically dock your QDockWidget ? Or modify the standard behavior ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MrRipple
          wrote on last edited by
          #4

          Hi SGaist,
          thanks for the reply!
          In the MyMainWindow::mouseMoveEvent() I create a new QDockWidget.
          I need, without user releases left button, to move this QDockWidget as the user has clicked on the title bar of QDockWidget.
          If, in MyMainWindow::mouseMoveEvent(), I use QDockWidget::move(QCursor:: pos()) method I can change the position of QDockWidget but it is not dockable!

          thanks

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Where should the user press the mouse button ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • M Offline
              M Offline
              MrRipple
              wrote on last edited by
              #6

              Hi,
              what i need to do is a "custom drag&drop".
              In the left dock area I have a QDockWidget with a QListWidget. The list is a text list of plugin name. Every plugin is a widget that user can dock to the right dock area clicking on the desired plugin name and dragging and dropping it in the right dock area.

              So, when the user drags the desired plugin name from QListWidget:

              • in MyMainWindow::mousePressEvent(), I get a pointer of a QListWidgetItem.

              • in MyMainWindow::mouseMoveEvent(), according to the text of QListWidgetItem pointer, I create a new floating QDockWidget (movable, flotable and dockable to the right area).

              At this point I have only created a new user-desired QDockWidget.
              But how I can move this QDockWidget and attach it into the right dock area (how I can continue the drag&drop)?

              I need to attach new QDockWidget to mouse cursor without the user releases left-button and I need that QDockWidget behavior is as a standard drag&drop QDockWidget behavior (as the user drag&drop it from QDockWidget title bar).

              If in MyMainWindow::mouseMoveEvent(), after new QDockWidget creation, I use the QDockWidget::move(QCursor:: pos()) method I can move the new floating QDockWidget but it’s not dockable and if I want dock the new QDockWidget I need to release mouse button and press button on QDockWidget title bar… so i can move it and it’s dockable.

              Thanks

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Can that dock widget area be empty ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  MrRipple
                  wrote on last edited by
                  #8

                  No, there is already a first QDockWidget in the dock area,

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    It's not that I don't like your idea but it feels strange to me that starting to drag an item it magically becomes a widget. What I would suggest is that you use the already existing drag & drop facility of the QListWidget (you can customize the look the dragged element if you need) and only react on the drop of that item in the MainWindow area where the dock widget should be and when dropping you create the new QDockWidget with all what it needs.

                    Hope it helps

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    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