Unsolved what is the best way to distinguish the a single QGraphicsItem Visually from other QGraphicsitems in the QGraphicsView
-
On continuation of this topic
What is the best way to distinguish he a single QGraphicsItem from other QGraphicsitems in the QGraphicsView -
Depends on what you want to distinguish (e.g. just item type? or item identity?), and for what use case.
-
A rectangle from rest of other rectangles ?
-
Ok, let's say you have 10 QGraphicsRectItem instances in your scene, and you want to remember one of them.
If it's sufficient to remember it during the life time of the scene, the pointer works fine. It's unique, and it doesn't change as you change the position, color and other aspects of the rectangle.However, it really depends on what you want to do with it. For example, the pointers work fine if you want to save and restore item selection. Say, the user has selected 3 rectangles, and wants to save this selection for sometimes later. You can save the three pointers. In this case, you need to remember that an item might have been deleted, so you have to take care of that case without crashing your application.
But that's just one example. If you describe in more detail what you try to achieve, we can discuss more specifically suited approaches.
-
I want to differentiate graphically and visually one rectangle from others , I cannot use colors and styles to differentiate
-
@Qt-Enthusiast said in what is the best way to distinguish the a single QGraphicsItem Visually from other QGraphicsitems in the QGraphicsView:
I want to differentiate graphically and visually one rectangle from others , I cannot use colors and styles to differentiate
What output do you want? For example, do you just want to know "Rectangle A looks different than Rectangle B", or do you want detailed information on what is different? Or do you want to have a difference image showing how exactly the rectangles differ?
And what do you mean by "I cannot use colors and styles to differentiate"? -
@Asperamanca said in what is the best way to distinguish the a single QGraphicsItem Visually from other QGraphicsitems in the QGraphicsView:
What output do you want? For example, do you just want to know "Rectangle A looks different than Rectangle B", or do you want detailed information on what is different? Or do you want to have a difference image showing how exactly the rectangles differ?
I have 10 rectangles out of which I want one rectangle to stand apart from others
I cannot make one rectangles as color blue and rest as red . I cannot use styles to differentiate between the rectangles
-
how to use QGraphicsPixmapItem for this ?
-
@Qt-Enthusiast said in what is the best way to distinguish the a single QGraphicsItem Visually from other QGraphicsitems in the QGraphicsView:
@Asperamanca said in what is the best way to distinguish the a single QGraphicsItem Visually from other QGraphicsitems in the QGraphicsView:
What output do you want? For example, do you just want to know "Rectangle A looks different than Rectangle B", or do you want detailed information on what is different? Or do you want to have a difference image showing how exactly the rectangles differ?
I have 10 rectangles out of which I want one rectangle to stand apart from others
I cannot make one rectangles as color blue and rest as red . I cannot use styles to differentiate between the rectangles
I think I misunderstood your original intentions then. If you say, you want one rectangle to stand apart, that sound like you want to highlight certain items, for example like when you select a file in a file explorer.
One approach I use is to create a child element to the element I want to highlight, and remove it once I don't want the highlight anymore.
There are several possibilities on how to use it, depending on what visual effect you want:- You could make the child item like a small marker in one corner of your rectangle
- You could make the child item semi-transparent and put it on top of the rectangle
- You could make the child item larger than the rectangle, and put it behind the rectangle in z order (you need to set the flag QGraphicsItem::ItemStacksBehindParent on the child item to achieve this effect)
-
sample code will be helpful