Qt World Summit: Submit your Presentation

mouseMoveEvent problems

  • I'm having a problem with mouseMoveEvent. I've got some widgets that I'm dragging and dropping around. I'm doing fine with mousePressEvent, mouseMoveEvent and mouseReleaseEvent up to a point. I want to pick a widget up, out of its parent window and set it free, or put it in another parent window.

    When I click on the widget, I catch the mousePressEvent and call: setParent(topWindow, Qt::Tool | Qt::FramelessWindowHint | Qt::CustomizeWindowHint); where topWindow is a top level QMainWindow. The problem is that this eventually calls QWidgetPrivate::deactivateWidgetCleanup() which sets qt_button_down = 0. This makes it impossible to catch further mouseMoveEvents, even though the mouse button is still down over the widget.

    Is there some way to set qt_button_down back to myWidgetPointer? Or maybe send my own mousePressEvent which will then set qt_button_down back to myWidgetPointer?

    Thanks for any help.

  • Ok, I've solved this -- or at least found a work-around. Wrap the setParent() function with setAttribute(Qt::WA_WState_Hidden, true); and setVisible(true); like this:

    setAttribute(Qt::WA_WState_Hidden, true);
    setParent(topWindow, Qt::Tool | Qt::FramelessWindowHint | Qt::CustomizeWindowHint);

    This fools Qt into thinking the widget wasn't shown in the first place so it doesn't remove its mouse-button-down state.

Log in to reply