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. Drag in QGraphicsView

Drag in QGraphicsView

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

    Hello!

    I have a problem with my QGraphicsView object. I put an image inside it but the image is bigger than the QGraphicsView so, when I move the mouse over the image, the image moves too. I don't want this effect. It is like when I drag the image but without pressing it.

    How can I fix it?

    Thank you very much!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Do you mean when you move the item which contains that big image ?

      Can you share the code you use ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • ivanicyI Offline
        ivanicyI Offline
        ivanicy
        wrote on last edited by
        #3

        Yes, when I run the application, it has a QGraphicsView with an image. The problem is that I can move the image without doing drag, if I move the mouse over the image, I can move it, but this situation only should happen when I do drag on the image. I put the mouseTracking on because I need the image's coordinates.

        I would share my code, but it is very long.

        Thank you very much!!

        1 Reply Last reply
        1
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Can you show your code ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          ivanicyI 1 Reply Last reply
          1
          • SGaistS SGaist

            Can you show your code ?

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

            @SGaist Ok, here is my code.

            This is the constructor of my QGraphicsView class:

            imageView::imageView(QWidget *parent)
            {
                /* Inicialización de elementos gráficos **************************************** */
                scene = new QGraphicsScene();
                this->setScene(scene);
                //this->resize(788, 1044);
            
                item = new QGraphicsPixmapItem();
            
                scene->addItem(item);
                this->setMouseTracking(true);
                this->scene->setItemIndexMethod(QGraphicsScene::NoIndex);
                connect(scene, &QGraphicsScene::selectionChanged, this, &imageView::applySelection);
                //item->setFlag(QGraphicsPixmapItem::ItemIsMovable, false);
                //this->show();
            
                this->setCacheMode(CacheBackground);
                this->setViewportUpdateMode(BoundingRectViewportUpdate);
                this->setRenderHint(QPainter::Antialiasing);
                this->setTransformationAnchor(AnchorUnderMouse);
            }
            

            And this is my declaration code:

            In *.h

            QSharedPointer<imageView> thermalImage;
            

            In *.cpp

            thermalImage.reset(new imageView(this));
            // Al connects...
            ui->imageLayout->addWidget(thermalImage.data());
            

            Thank you.

            1 Reply Last reply
            1
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Can you provide a complete minimal sample ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1

              • Login

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