I know that its kinda late, but I solved this issue. The code is very similar to the implementation that Farhad suggested, but to solve the "jumping" window, you need to update the current position of the mouse also in the event filter:
if (object == ui->frame_title && event->type() == QEvent::MouseButtonPress)
{
QMouseEvent* mouseEvent = (QMouseEvent*)event;
if (pressed == false){
current = mouseEvent->pos();
}
pressed = true;
return true;
}
Adding this, you get the current mouse location when the user first press the left-click.
Here is the full implementation:
void MainWindow::mousePressEvent(QMouseEvent *event)
{
current = event->pos();
}
void MainWindow::mouseMoveEvent(QMouseEvent *event)
{
if(pressed)
this->move(mapToParent(event->pos() - current));
}
bool MainWindow::eventFilter(QObject *object, QEvent *event)
{
if (object == ui->frame_title && event->type() == QEvent::MouseButtonPress)
{
QMouseEvent* mouseEvent = (QMouseEvent*)event;
if (pressed == false){
current = mouseEvent->pos();
}
pressed = true;
return true;
}
if (object == ui->frame_title && event->type() == QEvent::MouseButtonRelease)
{
pressed = false;
return true;
}
else
return false;
}
Then in your constructor, just add (frame_title is my titlebar):
ui->frame_title->installEventFilter(this);