This comes close:
if(!moving) this->grabMouse();
ui.label->setText("moving");
}
this->move(pos() + (event->globalPos() - position));
position = event->globalPos();
}
if(event
->type
() == QEvent::MouseButtonPress) position
= event
->globalPos
();
}
void frmDialog
::mouseReleaseEvent(QMouseEvent * event
){ ui.label->setText("release");
this->releaseMouse();
moving = false;
}
void frmDialog::moveEvent(QMoveEvent * event){
if(!moving) this->grabMouse();
ui.label->setText("moving");
}
void frmDialog::mouseMoveEvent(QMouseEvent * event){
this->move(pos() + (event->globalPos() - position));
position = event->globalPos();
}
void frmDialog::mousePressEvent(QMouseEvent * event){
if(event->type() == QEvent::MouseButtonPress) position = event->globalPos();
}
void frmDialog::mouseReleaseEvent(QMouseEvent * event){
ui.label->setText("release");
this->releaseMouse();
moving = false;
}
To copy to clipboard, switch view to plain text mode
Still some small bugs in there, but you get it to work. If not, you know where to ask
.
[edit]
Small explination:
Grabbing the mouse when the dialog is moved will make Qt post the mouse events, which normally go somewhere else, to the dialog. You can then catch them to move the dialog(becausse Qt won't do it for you anymore) and know when the user stops to move it.
And then don't forget to release the mouse again, or you won't have any mouse event's in your desktop untill you kill the application(without the use of the mouse off course).
Cheers,
Bart.
Bookmarks