Important: Please read the Qt Code of Conduct -

MouseEvent ruined when ...

  • Hi Qt Community ,

    I subclassed a QGraphicsView to gain access to slots , and especialy QMouseMoveEvent , my view's scene contains a subclassed QGraphicsItem that grabs my mouse events .

    To be precise , i coded my mouseMoveEvent to calculate the length between the cursor and my subclassed item , and it works just fine .

    But , when i configured my view to ensureVisible(myItem,x,y) , the calculations got ruined , and after several tests , i realized what's the problem.

    For it to be fixed , i want to catch my item's "view pos" ( or "widget pos" just to help being clear) because , ensure visible being active all the time with a QTimer , when the item goes to its margins , its item.pos() changes but he stands still in the view [Normal]

    So any ideas how to catch my item's "view pos" ?

    Thanks for your comprehension and sorry for the long post :b

  • Omg , i just realized the topic isn't as ridiculous as it looks .
    The problem isn't in the item's pos nor view pos ...
    The problem is in the QMouseEvent ... (Someone : Wow how genius) but wait ...

    Since i'm using a QMouseEvent instead of a QGraphicsSceneMouseEvent , i catch the event->pos() , which is strictly relative to the view .
    So when the view "moves" with the effect of ensureVisible(item,x,y) while NOT moving my mouse , the event->pos() remains the same ! [Normal again]

    So to fix that , i want to catch my mouseEvent's scenePos , which i heard is only accessible when using QGraphicsSceneMouseEvent , but when i tried that ,the view didn't catch the event T-T

    Someone volunteer to help me get the QGraphicsSCeneMouseEvent working , I'll be grateful ;)

  • Should i subclass a QGraphicsScene ?

  • Yep , fixed !!

    Biggest achievement of ma layf.