Qt World Summit: Register Today!

Can't stop mousemoves from affecting cursor.

  • Hi,

    I am trying to intercept all mouseMove events so that I can confine the cursor to a section of the top widget's window. I installed an eventFilter on the qApp, but even if I capture all events using event->accept() and return true, the app's cursor is still drawn and still follows my mouse everywhere, unconstrained.

    Incidentally by capturing all events I'm stopping all paint events...the only thing that is drawn is the cursor! I did try just filtering on mouseMove events but since stopping them didn't stop the cursor, I broadened the eventFilter to intercept everything. Only it still does not stop cursor movement.

    I also tried stopping/accepting all events in a subclassed QApplication::notify but no: The cursor is still painted and still follows the mouse.

    Where is the event that controls the app's cursor draw/paint? How do I intercept it?

    bool MyWidget::eventFilter(QObject *obj, QEvent *event)
      static int county = 0;
      qDebug("%s county %d  event->type() %d", __FUNCTION__, county++, event->type());
      qDebug(" ACCEPTING and returning true");
      return true;

    and in the qApp:

    myWidget = new* MyWidget(0);  // it's a window...could that be the problem?

    Thanks for any help.

  • OK I have made significant progress by just resetting the cursor position when I want to as recommended in this SO post: link.

    It just overrides mouseMoveEvent for a given widget and uses the static function QCursor::setPos to, for example, limit the cursor to some region in the widget.

    But the question remains: In an eventFilter that is set on the qApp, why can't I intercept all mouseMove events before the cursor is drawn?

    Am I not installing the eventFilter in the right place?

    Should I try nativeEventFilter (though I want to avoid this to remain portable)?

  • mouse move is system generated message. You can't stop it from generating them.
    It would be funny to prevent user from moving mouse. Perfect virus.

  • Thanks. I can probably understand why Qt wouldn't want to allow the developer to block all (mouse) input, but docs are not clear about this issue.