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 highlight empty Area in QGraphicsScene?
Qt 6.11 is out! See what's new in the release blog

How to highlight empty Area in QGraphicsScene?

Scheduled Pinned Locked Moved Unsolved General and Desktop
16 Posts 4 Posters 1.5k Views 3 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.
  • A Offline
    A Offline
    Akhendra
    wrote on last edited by
    #1

    Hi All,

    I am adding QPixmap which is source raw Image data to QGraphicsScene and some customs items(Rect,Polygon,PixmapItem ..etc) added to QGraphicsScene.
    Now i want to highlight only(using color) visible area(empty area) of QPixmap which is not covered with the custom items in QGraphicsScene.

    Please tell me a good way of highlight empty area?

    raven-worxR 1 Reply Last reply
    0
    • A Akhendra

      Hi All,

      I am adding QPixmap which is source raw Image data to QGraphicsScene and some customs items(Rect,Polygon,PixmapItem ..etc) added to QGraphicsScene.
      Now i want to highlight only(using color) visible area(empty area) of QPixmap which is not covered with the custom items in QGraphicsScene.

      Please tell me a good way of highlight empty area?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @Akhendra
      you can use QGraphicsView::drawBackground()

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      A 1 Reply Last reply
      0
      • raven-worxR raven-worx

        @Akhendra
        you can use QGraphicsView::drawBackground()

        A Offline
        A Offline
        Akhendra
        wrote on last edited by
        #3

        @raven-worx
        As per Qt document:
        Draws the background of the scene using painter, before any items and the foreground are drawn. Reimplement this function to provide a custom background for this view.

        So here i am adding a QPixmap to a scene after view is created and also custom items are also added.
        I cant see any thing.

        A 1 Reply Last reply
        0
        • A Akhendra

          @raven-worx
          As per Qt document:
          Draws the background of the scene using painter, before any items and the foreground are drawn. Reimplement this function to provide a custom background for this view.

          So here i am adding a QPixmap to a scene after view is created and also custom items are also added.
          I cant see any thing.

          A Offline
          A Offline
          Akhendra
          wrote on last edited by
          #4

          Hello Guys,

          Any ideas or solutions????

          Pl45m4P 1 Reply Last reply
          0
          • A Akhendra

            Hello Guys,

            Any ideas or solutions????

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

            @Akhendra

            So your PixMap Item is your background and on that background you put other QGraphicItems?

            You could check each point covered by your PixMap item whether there is one of your QGraphicsItems or not. Then repaint this point/area.


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

            ~E. W. Dijkstra

            A 1 Reply Last reply
            0
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi
              So the pixmap is covering all of the background?

              And you place some Items in some locations and you want to show remaining space (on the pixmap) that
              is not covered with an item ?

              Is the pixmap just blank or is there some area where Items are allowed and some not?

              Could you show how it looks ?
              (use postimage.org (or similar) as image upload is still broken here)

              A 1 Reply Last reply
              0
              • mrjjM mrjj

                Hi
                So the pixmap is covering all of the background?

                And you place some Items in some locations and you want to show remaining space (on the pixmap) that
                is not covered with an item ?

                Is the pixmap just blank or is there some area where Items are allowed and some not?

                Could you show how it looks ?
                (use postimage.org (or similar) as image upload is still broken here)

                A Offline
                A Offline
                Akhendra
                wrote on last edited by
                #7

                @mrjj
                The pixmap is not blank, actually it is Image of data contains lets say photo clicked from camera and added this as a pixmap to scene.
                The pixmap is covering all of the background and on top of that i am just adding items(PixmapItem,RectItem, etc).
                Find the sampled image with items drawn on top.
                https://i.postimg.cc/d3BFrTMZ/Capture.jpg
                https://postimg.cc/D48RK0w7

                1 Reply Last reply
                0
                • Pl45m4P Pl45m4

                  @Akhendra

                  So your PixMap Item is your background and on that background you put other QGraphicItems?

                  You could check each point covered by your PixMap item whether there is one of your QGraphicsItems or not. Then repaint this point/area.

                  A Offline
                  A Offline
                  Akhendra
                  wrote on last edited by
                  #8

                  @Pl45m4
                  Thank you. This one kind of solution.
                  But it take more time to find out due to image resolution.
                  I am just exploring other alternative approaches.

                  mrjjM 1 Reply Last reply
                  0
                  • A Akhendra

                    @Pl45m4
                    Thank you. This one kind of solution.
                    But it take more time to find out due to image resolution.
                    I am just exploring other alternative approaches.

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by mrjj
                    #9

                    @Akhendra
                    So when user press Add item, he is given one of some size. Lets say 200x200

                    You then want app to draw/highlight in some way all areas that could hold this item without this overlapping?

                    like this ?
                    alt text

                    Since you also have no rectangular areas, the placement method needs to be more clever than
                    simply dividing the pixmap into a grid.
                    Do you need to go tight on the polygons ? Or would its bouncing area be good enough ?

                    Is the Item, you insert always the same size to begin with?
                    or do different items come in different start sizes?

                    A 1 Reply Last reply
                    0
                    • mrjjM mrjj

                      @Akhendra
                      So when user press Add item, he is given one of some size. Lets say 200x200

                      You then want app to draw/highlight in some way all areas that could hold this item without this overlapping?

                      like this ?
                      alt text

                      Since you also have no rectangular areas, the placement method needs to be more clever than
                      simply dividing the pixmap into a grid.
                      Do you need to go tight on the polygons ? Or would its bouncing area be good enough ?

                      Is the Item, you insert always the same size to begin with?
                      or do different items come in different start sizes?

                      A Offline
                      A Offline
                      Akhendra
                      wrote on last edited by
                      #10

                      @mrjj
                      The items are not same size and items come in different start sizes also.
                      As you mentioned, when ever i added a item then if i ask for empty area then it should highlight/draw(area which is not hold by item).

                      Mainly i need this empty area to fill(bucket fill) lets say if i want fill the empty area with pink color which is one of the item's color,so that the whole empty area become part of another item's area.

                      I hope you understood.
                      Thanks for reply.

                      mrjjM 1 Reply Last reply
                      0
                      • A Akhendra

                        @mrjj
                        The items are not same size and items come in different start sizes also.
                        As you mentioned, when ever i added a item then if i ask for empty area then it should highlight/draw(area which is not hold by item).

                        Mainly i need this empty area to fill(bucket fill) lets say if i want fill the empty area with pink color which is one of the item's color,so that the whole empty area become part of another item's area.

                        I hope you understood.
                        Thanks for reply.

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        @Akhendra
                        Ok, so it's very dynamic.
                        Does this "filling" come after user placed all floating areas ?
                        Or is that a way to sort of extend an existing items area ?

                        • if i ask for empty area then it should highlight/draw(area which is not hold by item).
                          So it should show one possible location and not all possible locations?
                        A 1 Reply Last reply
                        0
                        • mrjjM mrjj

                          @Akhendra
                          Ok, so it's very dynamic.
                          Does this "filling" come after user placed all floating areas ?
                          Or is that a way to sort of extend an existing items area ?

                          • if i ask for empty area then it should highlight/draw(area which is not hold by item).
                            So it should show one possible location and not all possible locations?
                          A Offline
                          A Offline
                          Akhendra
                          wrote on last edited by
                          #12

                          @mrjj
                          is that a way to sort of extend an existing items area ? Yes.

                          • if i ask for empty area then it should highlight/draw(area which is not hold by item).
                            So it should show one possible location and not all possible locations?==> It should show all possible locations which is not hold by items.
                          mrjjM 1 Reply Last reply
                          0
                          • A Akhendra

                            @mrjj
                            is that a way to sort of extend an existing items area ? Yes.

                            • if i ask for empty area then it should highlight/draw(area which is not hold by item).
                              So it should show one possible location and not all possible locations?==> It should show all possible locations which is not hold by items.
                            mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by mrjj
                            #13

                            Hi
                            Ok so these highlighted areas are shown as postions for the new item you are about to put in so rect for a rect
                            and polyshape for other forms ?

                            And not like non regular area of free space ?

                            alt text

                            Ugly, but the point is that the highlight area be the same shape the to be inserted item and
                            not like a blob ish ? ( as in picture)

                            A 1 Reply Last reply
                            0
                            • mrjjM mrjj

                              Hi
                              Ok so these highlighted areas are shown as postions for the new item you are about to put in so rect for a rect
                              and polyshape for other forms ?

                              And not like non regular area of free space ?

                              alt text

                              Ugly, but the point is that the highlight area be the same shape the to be inserted item and
                              not like a blob ish ? ( as in picture)

                              A Offline
                              A Offline
                              Akhendra
                              wrote on last edited by
                              #14

                              @mrjj
                              so these highlighted areas are shown as postions for the new item you are about to put in so rect for a rect
                              and polyshape for other forms ?==> It is polyshape so that i can add to another ployshape(polygon) or mask.

                              but the point is that the highlight area be the same shape the to be inserted item ==> No. It would be polyshape(like polygon or mask).

                              My main aim is to add empty area to either existing polyshape(polygon) item or mask(pixel mask) item.
                              I hope you understood the context.
                              Thank you for extended support.

                              mrjjM 1 Reply Last reply
                              0
                              • A Akhendra

                                @mrjj
                                so these highlighted areas are shown as postions for the new item you are about to put in so rect for a rect
                                and polyshape for other forms ?==> It is polyshape so that i can add to another ployshape(polygon) or mask.

                                but the point is that the highlight area be the same shape the to be inserted item ==> No. It would be polyshape(like polygon or mask).

                                My main aim is to add empty area to either existing polyshape(polygon) item or mask(pixel mask) item.
                                I hope you understood the context.
                                Thank you for extended support.

                                mrjjM Offline
                                mrjjM Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on last edited by mrjj
                                #15

                                @Akhendra
                                Hi
                                Ok so that is far more complex than i thought at first.
                                It sounds more like a selection tool in a paint application than simply placement of polygons with anti overlapping detection.

                                If you want to select/highlight the pixels in the free area(s), im not sure how we can
                                do that in any fast way as we would have to have a pixel buffer and subtract the pixel area where there are items. Since its polygons, this would be heavy for a big image.

                                Well now that is clear what you are after,
                                let's see if we can get lucky and someone knows a fast way to
                                do this with Qt. Sadly I'm not expert in graphical algorithms but other here might be :)

                                A 1 Reply Last reply
                                0
                                • mrjjM mrjj

                                  @Akhendra
                                  Hi
                                  Ok so that is far more complex than i thought at first.
                                  It sounds more like a selection tool in a paint application than simply placement of polygons with anti overlapping detection.

                                  If you want to select/highlight the pixels in the free area(s), im not sure how we can
                                  do that in any fast way as we would have to have a pixel buffer and subtract the pixel area where there are items. Since its polygons, this would be heavy for a big image.

                                  Well now that is clear what you are after,
                                  let's see if we can get lucky and someone knows a fast way to
                                  do this with Qt. Sadly I'm not expert in graphical algorithms but other here might be :)

                                  A Offline
                                  A Offline
                                  Akhendra
                                  wrote on last edited by
                                  #16

                                  @mrjj
                                  Yes you are right. I think graphicsview framework does not have direct API which can give empty area or it might have some other way.
                                  But i sincerely appreciate your effort and patience for giving the reply.
                                  Thank you MRJI

                                  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