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. QGraphicsPixmapItem selection is not consistent
Forum Updated to NodeBB v4.3 + New Features

QGraphicsPixmapItem selection is not consistent

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 519 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
    Sridharan
    wrote on last edited by Sridharan
    #1

    Hi,

    I am using Qt 5.12.7. I have added QGraphicsPixmapItem (image) to scene. This image has white background. Image gets selected on clicking portion of image with non-white color. Image gets deselected if i select white background except rectangular white background in the middle of image. My expectation is image should always gets selected if i click on any portion of image irrespective of colorAnalysis.png

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Asperamanca
      wrote on last edited by
      #6

      The selection mechanism uses hit testing (i.e. do I "hit" the item at a certain coordinate)?
      This works by calling QGraphicsItem::contains which by default calls QGraphicsItem::shape

      If you create an item yourself, you can reimplement either of these functions to get any behavior you want.

      S 1 Reply Last reply
      1
      • A Offline
        A Offline
        Asperamanca
        wrote on last edited by
        #2

        Easiest way would be to make the background of the image fully transparent. Then a click on that part of the image should not be recognized as a click on the QGraphicsPixmapItem anymore, and should deselect.

        S 1 Reply Last reply
        0
        • A Asperamanca

          Easiest way would be to make the background of the image fully transparent. Then a click on that part of the image should not be recognized as a click on the QGraphicsPixmapItem anymore, and should deselect.

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

          @Asperamanca

          I can not use transparent image always.
          Is there any configuration available for image selection based on background color ? If it is available, i can disable this configuration. Image used is PNG format

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Asperamanca
            wrote on last edited by
            #4

            Selection uses shape() of item for hit testing.
            So if you implement your own version of QGraphicsPixmap item, you could create your own shape that excludes the background of the image, however you define "background".

            Keep in mind that shape() function should be fast, so caching would be advised.

            S 1 Reply Last reply
            0
            • A Asperamanca

              Selection uses shape() of item for hit testing.
              So if you implement your own version of QGraphicsPixmap item, you could create your own shape that excludes the background of the image, however you define "background".

              Keep in mind that shape() function should be fast, so caching would be advised.

              S Offline
              S Offline
              Sridharan
              wrote on last edited by
              #5

              @Asperamanca

              I didnot understand your statement. Could you provide an example

              1 Reply Last reply
              0
              • A Offline
                A Offline
                Asperamanca
                wrote on last edited by
                #6

                The selection mechanism uses hit testing (i.e. do I "hit" the item at a certain coordinate)?
                This works by calling QGraphicsItem::contains which by default calls QGraphicsItem::shape

                If you create an item yourself, you can reimplement either of these functions to get any behavior you want.

                S 1 Reply Last reply
                1
                • A Asperamanca

                  The selection mechanism uses hit testing (i.e. do I "hit" the item at a certain coordinate)?
                  This works by calling QGraphicsItem::contains which by default calls QGraphicsItem::shape

                  If you create an item yourself, you can reimplement either of these functions to get any behavior you want.

                  S Offline
                  S Offline
                  Sridharan
                  wrote on last edited by
                  #7

                  @Asperamanca

                  You are correct. In my custom QGraphicsPixmapItem, shape() function is already reimplemented. I have done the changes needed in shape() and it's working now. Thanks

                  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