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. Is There a way to get Mouse Position in a sceneEventFilter?[Solved]
Qt 6.11 is out! See what's new in the release blog

Is There a way to get Mouse Position in a sceneEventFilter?[Solved]

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 4.7k Views 1 Watching
  • 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hello,

    I would listen in a QGraphicsItem mouse Events from other QGraphicsItems like this:

    @

    class item1 : public QGraphicsItem;
    {
    ......
    }

    class item2 : public QGraphicsItem;
    {
    bool sceneEventFilter(QGraphicsItem* watched, QEvent* event)
    {

        if (event->type() == QEvent::GraphicsSceneMouseMove) {
            QMouseEvent* mouse = static_cast<QMouseEvent*>(event);
            qDebug() << mouse->pos();
        }
    }
    

    }

    QGraphicsItem* item1 = new QGraphicsItem;
    QGraphicsItem* Item2 = new QGraphicsItem;

    item1->installSceneEventFilter(item2);

    @

    But output is definitly not correct, something like QPointF(141, 1.08089e+09).
    The Items are in the same Scene.

    Is there a way to get mouse coords in a sceneEventFilter?

    Thanks in advance, wesu

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      You should probably cast to QGraphicsSceneMouseEvent instead of QMouseEvent

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        Oh yeah i should... Thx you

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          Please mark the post title as [Solved]. Thanks

          1 Reply Last reply
          0

          • Login

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