QGraphicsPixmapItem selection is not consistent
-
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 color

-
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::shapeIf you create an item yourself, you can reimplement either of these functions to get any behavior you want.
-
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.
-
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.
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 -
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.
-
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.
I didnot understand your statement. Could you provide an example
-
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::shapeIf you create an item yourself, you can reimplement either of these functions to get any behavior you want.
-
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::shapeIf you create an item yourself, you can reimplement either of these functions to get any behavior you want.
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