Event when the QMouseMoveEvent is finished (released)?
-
QMouseReleaseEvent() is not called in my case.
Some more details: The widget is a TitelBarWidget which is set on a QDockWidget.
What I want to detect is when it has been moved (click titelbarwidget, move around, release mousue)
So maybee this is not a MouseMoveEvent but a MoveEvent? -
QMouseReleaseEvent() is not called in my case.
Some more details: The widget is a TitelBarWidget which is set on a QDockWidget.
What I want to detect is when it has been moved (click titelbarwidget, move around, release mousue)
So maybee this is not a MouseMoveEvent but a MoveEvent?mouseReleaseEvent
should be triggered, if you release the mouse button. It depends where you release the mouse.@gde23 said in Event when the QMouseMoveEvent is finished (released)?:
So maybee this is not a MouseMoveEvent but a MoveEvent?
MoveEvent is triggered, when you move the whole item or widget. That means, that you need to actually move the titlebar widget around on its parent window...
Do you want to drag / move something inside your
QDockWidget
or is it all about detecting the movement of theQDockWidget
window itself (then you can indeed use themoveEvent
)?
https://doc.qt.io/archives/qt-4.8/qwidget.html#moveEvent -
Ok, I did not know about MoveEvent.
What I want to do: By grabbing the titlebarwidget the whole widget is moved. This works.
However at the end of the move I want to update it (not all the time during move)
So I am searching for how to detect the end of the movement (when the mouse is released after moving) -
Ok, I did not know about MoveEvent.
What I want to do: By grabbing the titlebarwidget the whole widget is moved. This works.
However at the end of the move I want to update it (not all the time during move)
So I am searching for how to detect the end of the movement (when the mouse is released after moving)You can combine the
mousePressEvent
andmouseReleaseEvent
from your titlebar widget (The mouse stays within titlebar boundings during the movement, correct? Because it's standard dock window dragging behavior, with the only difference that you replaced the titlebar widget with a custom one?!) with the moveEvent from yourQDockWidget
.void TitleBarWidget::mousePressEvent(QMouseEvent *event) { m_aboutToMove = true; } void TitleBarWidget::mouseReleaseEvent(QMouseEvent *event) { if(m_hasMoved) { // UPDATE, send signal to update content // reset m_hasMoved afterwards } m_aboutToMove = false; }
void YourDockWidget::moveEvent(QMoveEvent *event) { if(m_aboutToMove) { m_hasMoved = true; // you could send a signal to titlebar widget and write a public function to notify the titlebar } }
Of course you can not access all the boolean from both classes directly... You'll need to write setters / getters or send signals.
It is just an example or idea how it can be done :) -
The mouse stays inside the titlebar (since it is moves along with it) and yes, I only replaced the titelbarwidget with my own version by setTitelBarWidget().
However I've tried using the MouseReleaseEvent, but it only is called when I do not move the mouse (move the widget) in between.
-
The mouse stays inside the titlebar (since it is moves along with it) and yes, I only replaced the titelbarwidget with my own version by setTitelBarWidget().
However I've tried using the MouseReleaseEvent, but it only is called when I do not move the mouse (move the widget) in between.
@gde23 said in Event when the QMouseMoveEvent is finished (released)?:
However I've tried using the MouseReleaseEvent, but it only is called when I do not move the mouse (move the widget) in between.
Which mouseReleaseEvent do you use? From titlebar widget or from your dockwidget
-
@J-Hilk
Here some code:
First The dockwidget gets a titlebar widget:
QDockWidget* dock = new QDockWidget(this); titleBarWidget = new MyTitleBarWidget(dock); dock->setTitleBarWidget(titleBarWidget);
The tiltebarwidget is just a QWidget with one single method added
void MyTitleBarWidget::mouseReleaseEvent(QMouseEvent *event) { std::cout << "mouse Released" << std::endl; QWidget::mouseReleaseEvent(event); }
Now when you click the titlebar and release it without moving the output is printed.
However when you click it, then move around and then release it is not printed to std out. -
@J-Hilk
Here some code:
First The dockwidget gets a titlebar widget:
QDockWidget* dock = new QDockWidget(this); titleBarWidget = new MyTitleBarWidget(dock); dock->setTitleBarWidget(titleBarWidget);
The tiltebarwidget is just a QWidget with one single method added
void MyTitleBarWidget::mouseReleaseEvent(QMouseEvent *event) { std::cout << "mouse Released" << std::endl; QWidget::mouseReleaseEvent(event); }
Now when you click the titlebar and release it without moving the output is printed.
However when you click it, then move around and then release it is not printed to std out.@gde23
this,
https://github.com/DeiVadder/QDockWidget-Test-111758
is a minimal reproducible example, and I can indeed reproduce it,as soon as the Docking mechanism is triggered(detach), the released signal is no longer emitted.
I would consider this a bug, but I haven't checked the source code to see, if its intended or not.
-
@gde23
this,
https://github.com/DeiVadder/QDockWidget-Test-111758
is a minimal reproducible example, and I can indeed reproduce it,as soon as the Docking mechanism is triggered(detach), the released signal is no longer emitted.
I would consider this a bug, but I haven't checked the source code to see, if its intended or not.
-
I finally found a method that works, that I want so share:
void myWidget::moveEvent(QMoveEvent *event) { Qt::MouseButtons mouse = qApp->mouseButtons(); if(mouse != Qt::LeftButton) { std::cout << "move end" << std::endl; } }
If you check the mouse status in the moveEvent(), on the last move event the mouse will not be pressed anymore, which is kind of like a mouse release event. At least it works for me at the moment.