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. Solved:How to implement lastScenePos()?
Forum Updated to NodeBB v4.3 + New Features

Solved:How to implement lastScenePos()?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 6.2k 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.
  • R Offline
    R Offline
    romeo.rbw
    wrote on last edited by
    #1

    Hi...
    according to Qt document:

    QPointF QGraphicsSceneMouseEvent::lastScenePos () const

    Returns the last recorded mouse cursor position in scene coordinates. The last recorded position is the position of the previous mouse event received by the view that created the event.

    I am not understand how to write it in application. Could you give me an example/suggestion how to write or implement this?

    Thank you.

    1 Reply Last reply
    0
    • R Offline
      R Offline
      rcari
      wrote on last edited by
      #2

      Could you explain your case? This event is generated by the QGraphicsView when it receives mouse events. You just have to use this method, you don't need to implement it: it's already done in Qt.

      1 Reply Last reply
      0
      • R Offline
        R Offline
        romeo.rbw
        wrote on last edited by
        #3

        Yes, I mean how to use it because I try like this but the coordinate not detected, always zero. I use buttonDownScenePos

        @
        QPointF DialogApplication::get_koordinat_mouse_klik(){

        QPointF mouse_koordinat;
        QEvent::Type type;
        QGraphicsSceneMouseEvent mouseEvent(type);
        
        //mouse_koordinat = mouseEvent.lastScenePos();
        mouse_koordinat=   mouseEvent.buttonDownScenePos(Qt::LeftButton);
        
        
        return mouse_koordinat;
        

        }
        @

        1 Reply Last reply
        0
        • R Offline
          R Offline
          rcari
          wrote on last edited by
          #4

          Well lastScenePos will only be provided if you are tracking the mouse: if it was clicked and dragged, or if you grabbed it. It will not be on the initial click.

          1 Reply Last reply
          0
          • I Offline
            I Offline
            issam
            wrote on last edited by
            #5

            I think it's better to use QGraphicsSceneMouseEvent::lastScenePos() inside one of those methods of the QGraphicsScene class :

            @
            virtual void mouseDoubleClickEvent ( QGraphicsSceneMouseEvent * mouseEvent )
            virtual void mouseMoveEvent ( QGraphicsSceneMouseEvent * mouseEvent )
            virtual void mousePressEvent ( QGraphicsSceneMouseEvent * mouseEvent )
            virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * mouseEvent )
            @

            so you have to reimplement them !

            http://www.iissam.com/

            1 Reply Last reply
            0
            • R Offline
              R Offline
              romeo.rbw
              wrote on last edited by
              #6

              Thank you very much issam and rcari. It's done well:
              @
              void MyItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
              {
              if(event->button()==Qt::LeftButton){
              myMouse_koordinat = event->buttonDownScenePos
              (Qt::LeftButton);
              qDebug() << myMouse_koordinat.x();
              }
              update();
              QGraphicsItem::mousePressEvent(event);
              }
              @

              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