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. Mouse tracking on QGraphicsView
Forum Updated to NodeBB v4.3 + New Features

Mouse tracking on QGraphicsView

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 3.4k 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.
  • ivanicyI Offline
    ivanicyI Offline
    ivanicy
    wrote on last edited by
    #1

    Hello!

    I have a class derivated of QGraphicsView. I had to enable the mouse tracking property because I have to get the mouse position coordinates. Now, the problem is that when I move the mouse on the QGraphicsView, I can move the image inside "without clicking it".

    How could I disable this first click?

    Ni.SumiN 1 Reply Last reply
    0
    • ivanicyI ivanicy

      Hello!

      I have a class derivated of QGraphicsView. I had to enable the mouse tracking property because I have to get the mouse position coordinates. Now, the problem is that when I move the mouse on the QGraphicsView, I can move the image inside "without clicking it".

      How could I disable this first click?

      Ni.SumiN Offline
      Ni.SumiN Offline
      Ni.Sumi
      wrote on last edited by Ni.Sumi
      #2

      @ivanicy

      Try setting to false,l setflag()

      setFlag(QGraphicsItem::ItemIsMovable, false);
      
      1 Reply Last reply
      1
      • ivanicyI Offline
        ivanicyI Offline
        ivanicy
        wrote on last edited by
        #3

        Thank you very much for answer me but this fix doesn't work. The problem is: at first, when I move the mouse, the image moves too, but, when I click the image, the movement stops, and I want to stop the movement always.

        1 Reply Last reply
        1
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          If image moves means u must be setting image coordinates with mouse move coordinates. Can u paste the sample code ?

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          ivanicyI 1 Reply Last reply
          2
          • dheerendraD dheerendra

            If image moves means u must be setting image coordinates with mouse move coordinates. Can u paste the sample code ?

            ivanicyI Offline
            ivanicyI Offline
            ivanicy
            wrote on last edited by
            #5

            @dheerendra This is my code section:

                /* MODO POR DEFECTO (ZOOM) ****************************************************************************** */
                if (graphicMode == ZOOM_MODE) {
                //if (sceneMode == NoMode) {
                    QPointF pos = this->mapToScene(event->pos());
                    int _posX = pos.x();
                    int _posY = pos.y();
                    if (this->hasMouseTracking() && !item->pixmap().isNull()) {
                        if (_posX >= 0 && _posX <= this->imageData.cols && _posY >= 0 && _posY <= this->imageData.rows)
                            if (analysisMode)
                                emit sendPos(this->mapToScene(event->pos()), this->imageTemp.ptr<double>(_posY)[_posX]);/************/
                            else emit sendPos(this->mapToScene(event->pos()), asignaTemperatura(C1*(double)this->imageData.ptr<short>(event->pos().y())[event->pos().x()] + C0, 1, tabla_L_T1));
                        else {
                            QPoint badPos(-1,-1);
                            emit sendPos(badPos, -1);
                        }
                    }
                    if (_pan)
                    {
                        horizontalScrollBar()->setValue(horizontalScrollBar()->value() - (event->x() - _panStartX));
                        verticalScrollBar()->setValue(verticalScrollBar()->value() - (event->y() - _panStartY));
                        _panStartX = event->x();
                        _panStartY = event->y();
                        event->accept();
                        return;
                    }
            
                    event->ignore();
                }
            

            Thank you very much!

            1 Reply Last reply
            0
            • dheerendraD Offline
              dheerendraD Offline
              dheerendra
              Qt Champions 2022
              wrote on last edited by
              #6

              Let me rephrase your question. You have QGraphicsView & inside the You have image with GraphicsItem. Based on the mouse click you would like to move the image. Since you have enabled mouse tracking, without clicking also image is moving. Is that the correct problem statement ?
              If yes, you would like do something like, without first click image should not move. Is that correct ?

              Dheerendra
              @Community Service
              Certified Qt Specialist
              http://www.pthinks.com

              ivanicyI 1 Reply Last reply
              0
              • dheerendraD dheerendra

                Let me rephrase your question. You have QGraphicsView & inside the You have image with GraphicsItem. Based on the mouse click you would like to move the image. Since you have enabled mouse tracking, without clicking also image is moving. Is that the correct problem statement ?
                If yes, you would like do something like, without first click image should not move. Is that correct ?

                ivanicyI Offline
                ivanicyI Offline
                ivanicy
                wrote on last edited by
                #7

                @dheerendra Yes, exactly, this is my problem. Thank you for translate my question haha.

                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