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. How to add an image at a specific area in QGraphicsScene

How to add an image at a specific area in QGraphicsScene

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 5 Posters 2.0k 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.
  • AdemMetinCALIA Offline
    AdemMetinCALIA Offline
    AdemMetinCALI
    wrote on last edited by
    #1

    Hi,

    I have an large image and i want to add this image to a specific area (in a rectange that i can enter the x,y,width and height) in QGraphicsScene. How can i do that ?

    JonBJ Pl45m4P 2 Replies Last reply
    0
    • AdemMetinCALIA AdemMetinCALI

      Hi,

      I have an large image and i want to add this image to a specific area (in a rectange that i can enter the x,y,width and height) in QGraphicsScene. How can i do that ?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @AdemMetinCALI
      I have never used graphics stuff, but wouldn't you do this on the QGrapicsItem by calling https://doc.qt.io/qt-5/qgraphicsitem.html#setPos?

      AdemMetinCALIA 1 Reply Last reply
      0
      • AdemMetinCALIA AdemMetinCALI

        Hi,

        I have an large image and i want to add this image to a specific area (in a rectange that i can enter the x,y,width and height) in QGraphicsScene. How can i do that ?

        Pl45m4P Offline
        Pl45m4P Offline
        Pl45m4
        wrote on last edited by
        #3

        @AdemMetinCALI

        You can use QGraphicsPixmapItem for this.

        QPixmap::scaled to scale the image (shrink, expand the image, then move whole item to given point (x, y) )


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        AdemMetinCALIA 1 Reply Last reply
        3
        • JonBJ JonB

          @AdemMetinCALI
          I have never used graphics stuff, but wouldn't you do this on the QGrapicsItem by calling https://doc.qt.io/qt-5/qgraphicsitem.html#setPos?

          AdemMetinCALIA Offline
          AdemMetinCALIA Offline
          AdemMetinCALI
          wrote on last edited by
          #4

          @JonB Thanks for your advice, but i cannot find any member functions or properties that solve my problem and i think that QGraphicsPixmapItem is more convenient for me.

          JonBJ 1 Reply Last reply
          1
          • AdemMetinCALIA AdemMetinCALI

            @JonB Thanks for your advice, but i cannot find any member functions or properties that solve my problem and i think that QGraphicsPixmapItem is more convenient for me.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @AdemMetinCALI Yes, now that @Pl45m4 posted that specific QGraphicsPixmapItem for your case it is best to use.

            1 Reply Last reply
            1
            • Pl45m4P Pl45m4

              @AdemMetinCALI

              You can use QGraphicsPixmapItem for this.

              QPixmap::scaled to scale the image (shrink, expand the image, then move whole item to given point (x, y) )

              AdemMetinCALIA Offline
              AdemMetinCALIA Offline
              AdemMetinCALI
              wrote on last edited by
              #6

              @Pl45m4 said in How to add an image at a specific area in QGraphicsScene:

              QPixmap::scaled to scale the

              Thanks for your advice, but i don't want to shrink the image. I want to display a portion of the image in specific area.

              JonBJ 1 Reply Last reply
              0
              • AdemMetinCALIA AdemMetinCALI

                @Pl45m4 said in How to add an image at a specific area in QGraphicsScene:

                QPixmap::scaled to scale the

                Thanks for your advice, but i don't want to shrink the image. I want to display a portion of the image in specific area.

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #7

                @AdemMetinCALI
                Then I think you should read https://forum.qt.io/topic/83380/how-to-partially-draw-a-qgraphicspixmapitem. Which is going to tell you not to use a QGraphicsPixmapItem after all, but a custom QGraphicsItem instead!

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

                  Hi,

                  If you want only a portion of your image, one way to do it is to load the original in a QImage and then use the copy method to retrieve only the part you want to show and make a QGraphicsPixmap from that.

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

                  AdemMetinCALIA 1 Reply Last reply
                  1
                  • SGaistS SGaist

                    Hi,

                    If you want only a portion of your image, one way to do it is to load the original in a QImage and then use the copy method to retrieve only the part you want to show and make a QGraphicsPixmap from that.

                    AdemMetinCALIA Offline
                    AdemMetinCALIA Offline
                    AdemMetinCALI
                    wrote on last edited by
                    #9

                    @SGaist Thanks for your suggestion, but i think your solution causes performance issues. I try to build a hud and it has many symbology. How can i deal with the performance issues?

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

                      Then exploit the fact that you can use the sceneRect property to only show the part you want from the picture.

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

                      AdemMetinCALIA 1 Reply Last reply
                      1
                      • SGaistS SGaist

                        Then exploit the fact that you can use the sceneRect property to only show the part you want from the picture.

                        AdemMetinCALIA Offline
                        AdemMetinCALIA Offline
                        AdemMetinCALI
                        wrote on last edited by
                        #11

                        @SGaist Thanks for your suggestion, but i want to add more picture in different areas of the scene. With the sceneRect how can i do that?

                        1 Reply Last reply
                        0
                        • JKSHJ Offline
                          JKSHJ Offline
                          JKSH
                          Moderators
                          wrote on last edited by
                          #12

                          @AdemMetinCALI said in How to add an image at a specific area in QGraphicsScene:

                          i want to add more picture in different areas of the scene.

                          I'm trying to understand your requirements. Could you please clarify:

                          1. How many "large images" are you using? Do you use the same "large image" all the time, or do you keep loading a different "large image"
                          2. Are you trying to cut the large image into smaller pieces, and draw each small piece in a different part of the scene?

                          If you answer "yes" to #2, that means you want to make sprites. See https://evileg.com/en/post/92/ for example.

                          i think your solution causes performance issues. I try to build a hud and it has many symbology. How can i deal with the performance issues?

                          Why do you think there are performance issues? How serious are they?

                          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                          1 Reply Last reply
                          2
                          • AdemMetinCALIA Offline
                            AdemMetinCALIA Offline
                            AdemMetinCALI
                            wrote on last edited by
                            #13

                            I solved my problem in 2 stpes: In the first step, I've created a new class derived from QWidget, add the image into this widget and i made this widget transparent. In the second step, i added this widget into 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