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. Crop pixmap from qgraphicsscene with qgraphicsItem
Forum Updated to NodeBB v4.3 + New Features

Crop pixmap from qgraphicsscene with qgraphicsItem

Scheduled Pinned Locked Moved Solved General and Desktop
qgraphicssceneqgraphicsitemqpixmap
6 Posts 3 Posters 2.7k Views 2 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.
  • S Offline
    S Offline
    sayan275
    wrote on last edited by
    #1

    I'm trying to crop pixmap of the qgraphicsScene with the qgraphicsItem. But not able to find proper API or approach to do so.

    void ImageGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
    {
        if(m_isMousePressed && m_isMagnifyModeEnabled)
        {
            QPointF pos = mouseEvent->scenePos();
            qDebug()<<__FUNCTION__<<pos;
            QRect rect(pos.x() - 150, pos.y() - 150, 150, 150);
            QPixmap cropped = m_Pixmap.copy(rect);
            cropped.save("C:/Users/uidk6742/Desktop/OUT.jpg");
        }
    .
    .
    }
    

    0_1562179712364_434ab511-5465-45c4-b3b6-2b6c568e5885-image.png

    In the image cropped from the scene, doesnt contain the qgraphicsItem drawn on the car.

    Please suggest any approach, by which we can crop the pixmap from scene with the qgraphicsItem.

    Regards,
    Sayan

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

      Hi,

      QRubberBand comes to mind for creating the selection rectangle. Then you can use it to perform your cropping.

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

      S 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        QRubberBand comes to mind for creating the selection rectangle. Then you can use it to perform your cropping.

        S Offline
        S Offline
        sayan275
        wrote on last edited by sayan275
        #3

        @SGaist I tried, Below is the output
        0_1562232427759_aabbd508-c78c-477e-9fbe-74abb9f12ba8-image.png

        But how to save the contents of the rubberband? I didn't find any api in QRubberband to get the contents in the rubberband?

        I google searched about QRubberband examples...and found most of are in QGraphicsItem's subclassed.

        I actually need to crop out from the qgraphicsscene with the qgraphicsitem on it.

        jsulmJ 1 Reply Last reply
        0
        • S sayan275

          @SGaist I tried, Below is the output
          0_1562232427759_aabbd508-c78c-477e-9fbe-74abb9f12ba8-image.png

          But how to save the contents of the rubberband? I didn't find any api in QRubberband to get the contents in the rubberband?

          I google searched about QRubberband examples...and found most of are in QGraphicsItem's subclassed.

          I actually need to crop out from the qgraphicsscene with the qgraphicsitem on it.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @sayan275 QRubberband is nor responsible for cropping an image. Use https://doc.qt.io/qt-5/qpixmap.html#copy for that.
          You can get the size of rubberband (for cropping) using https://doc.qt.io/qt-5/qwidget.html#geometry-prop

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • S Offline
            S Offline
            sayan275
            wrote on last edited by
            #5

            @jsulm size is not a problem. Please see my the top thread in this topic. I'm able to copy the pixmap from the scene, but not with the qgraphicsItem on it.

            with copy, we can get a particular item, as the image is a pixmapItem and the box is a rectItem. But both can't be grabbed as 1 pixmap and use copy on that pixmap.

            I'll look further if possible by something called ..widgetGrabber..(maybe) or else, I have to pass the whole scene to do the operation(which is not good approach).

            My requirement is a Magnifying Glass effect on the qgraphicsScene, when the user presses the left mouse and move the mouse.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              sayan275
              wrote on last edited by sayan275
              #6

              Hi,
              I got the expected output from grab(QRect)
              https://stackoverflow.com/questions/16362191/qt-grab-widget-and-save-image

              m_graphicsView->grab(rect).save("OUT.jpg");
              

              Thanks all.

              1 Reply Last reply
              3

              • Login

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