QDockWidget: difference between move() and mouse drag
-
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:
-
In MyMainWindow::mousePressEvent():
I get a pointer of a QListWidgetItem. The QListWidget is in a QDockWidget in LeftDockArea. -
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. -
-
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 ?
-
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
-
Where should the user press the mouse button ?
-
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
-
-
Can that dock widget area be empty ?
-
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