Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can't stop mousemoves from affecting cursor.
QtWS25 Last Chance

Can't stop mousemoves from affecting cursor.

Scheduled Pinned Locked Moved General and Desktop
eventfiltmousemovecursorcustom cursor
4 Posts 2 Posters 1.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    GeorgePTVS
    wrote on 20 Apr 2015, 22:38 last edited by
    #1

    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");
      event->accept();
      return true;
    }
    

    and in the qApp:

    myWidget = new* MyWidget(0);  // it's a window...could that be the problem?
    myWidget->setMouseTracking(true);
    qApp->installEventFilter(myWidget);
    

    Thanks for any help.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      GeorgePTVS
      wrote on 20 Apr 2015, 23:45 last edited by
      #2

      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)?

      1 Reply Last reply
      0
      • A Offline
        A Offline
        alex_malyu
        wrote on 21 Apr 2015, 00:13 last edited by
        #3

        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.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          GeorgePTVS
          wrote on 21 Apr 2015, 01:44 last edited by
          #4

          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.

          1 Reply Last reply
          0

          4/4

          21 Apr 2015, 01:44

          • Login

          • Login or register to search.
          4 out of 4
          • First post
            4/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved