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. Render just a specific area of a QGraphicsScene
Forum Updated to NodeBB v4.3 + New Features

Render just a specific area of a QGraphicsScene

Scheduled Pinned Locked Moved Unsolved General and Desktop
widgetsqgraphicssceneqgraphicsviewrender to imagerubber band
5 Posts 3 Posters 895 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.
  • N Offline
    N Offline
    nitro0
    wrote on last edited by
    #1

    Hello all, relatively new here, but I came across some cool posts in the past and now I have a very own problem trying to being solved. Hope you could help out here!

    So I catch the rubberBandChanged signal and return the values I require to get the underlying part of the QGraphicsScene. QRect rect, QPointF from, QPointF to). With that I should be able to render just the part of the current QGraphicsScene, I selected with the rubberBand:

    // EditorView is a QGraphicsView
    void EditorView::imageFromRectRequested(const QRect &_rect, const QPointF &_from, const QPointF &_to) {
        QImage _img(_rect.size(), QImage::Format_ARGB32);
        QPainter _p(&_img);
        this->scene()->render(&_p, _img.rect(), _rect);
    
        _img.save("Z:\\Documents\\test.png");
    }
    

    It does render a part of the QGraphicsScene, with the correct size, but not with the correct position. Where do I do something wrong, what do I misunderstood about that concept?

    Any help appreciated!

    Many thanks!
    nitroo

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

      Hi and welcome to devnet,

      Did you map the coordinates to the scene at some point ?

      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
      • N Offline
        N Offline
        nitro0
        wrote on last edited by nitro0
        #3

        Hi @SGaist,

        thank you for your welcome!

        No, currently not. I thought this->scene()->render() does the trick on the current scene. Where do I need to map the coordinates I get from the QGraphicsView rubberband in order to get the underlying part of the image? I don't know where to really add the coordinates..

        ~nitroo

        1 Reply Last reply
        0
        • N nitro0

          Hello all, relatively new here, but I came across some cool posts in the past and now I have a very own problem trying to being solved. Hope you could help out here!

          So I catch the rubberBandChanged signal and return the values I require to get the underlying part of the QGraphicsScene. QRect rect, QPointF from, QPointF to). With that I should be able to render just the part of the current QGraphicsScene, I selected with the rubberBand:

          // EditorView is a QGraphicsView
          void EditorView::imageFromRectRequested(const QRect &_rect, const QPointF &_from, const QPointF &_to) {
              QImage _img(_rect.size(), QImage::Format_ARGB32);
              QPainter _p(&_img);
              this->scene()->render(&_p, _img.rect(), _rect);
          
              _img.save("Z:\\Documents\\test.png");
          }
          

          It does render a part of the QGraphicsScene, with the correct size, but not with the correct position. Where do I do something wrong, what do I misunderstood about that concept?

          Any help appreciated!

          Many thanks!
          nitroo

          W Offline
          W Offline
          wrosecrans
          wrote on last edited by
          #4

          @nitro0 It seems worth noting that you pass _from and _to to your function, but never use them. Did you intend to? If not, I am confused why they are part of the signature.

          I'd guess that rect you are using is just in the "wrong position" and you don't include anything about how exactly it is made, or what is wrong about it.

          1 Reply Last reply
          0
          • N Offline
            N Offline
            nitro0
            wrote on last edited by
            #5

            @wrosecrans
            I know that I need them. But don‘t know how to apply them on the scene and keep everything thats on that. I thought that the rect itself has the points in it using the render function of the QGraphicsScene is enough.

            What I do: I set the DragMode of the QGraphicsView to rubberband so the user can select some part pf the scene by simply dragging. The returned rect is now sent to the view to get the underlying image of the scene.

            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