How to easily recognize searched item in a dense QGraphicsScene? - qt

I have a QGraphicsScene with many QGraphicsItem like circle, rectangle, polylines, arc etc.
Every QGraphicsItem has a name. And I have a Search feature which highlights searched items using that name. When scene contains fewer items, highlighted items are seen properly. But when scene contains many items ( 100 + ) then identifying the highlighted item becomes difficult. For that I need to scroll up - down or left - right to check where is that highlighted item is.
So I want my highlighted item to be easily recognizable.
For that I was suggested, some approach like
Take searched item in front
Or
Add some marker
But I do not know, how to implement it , which Qt class should I use etc.

QGraphicsScene displays items depending on their stacking, i.e., when you call .items(), the first item in the QList is the topmost item on the scene.
The ordering of the items is depending on their respective Z-values which you can set for the QGraphicsItem by calling .setZValue()
You can read more about this on the following link: https://doc.qt.io/qt-5/qgraphicsitem.html#sorting
As for your question on how to put them in front. If you implemented your own children classes of QGraphicsItem, you can add a method or a slot to toggle them "on-top". E.g., all of the items usually have a Z-order of 0, so your method could just set it to 1 when the item is highlighted and revert it to 0 when it's not.

Related

In Graphic scene how to make overlapped object transparent?

In graphics view m setting scene in that adding objects (by dropping ), i can move these items by mouse, when i moved one object on another object moved object should be transparent. how can i make it?
I don't believe you actually want full transparency since it will make it impossible to visually recognize the transparent object later on. Reduced opacity - yes.
As for your question: each item inside your scene has a bounding rectangle (or other type of bounding area). You can easily get it by calling boundingRect() of your item. The returned QRectF has (just like QRect) has the bool QRect::intersects(const QRect &rectangle) const function, which takes another rectangle and checks if a collision is present.
Whenever you move your mouse while dragging an item you need to iterate either through all or just a subset of all items in your scene (by subset I mean just the items in a specific region to increase the performance) and check for collision. If a collision is detected, you can alter either the item you are dragging or the item underneath it.
Of course to make sure that one item covers another one you also need to check the Z value. The easiest way to do that is if you keep all currently not being dragged items at the same Z level and then, whenever you drag one, increase it's Z level by one so that it is "above" the others.

How to pass hoverMoveEvent to underlaying items

I have custom graphic item that draws some figure consisting of lines and polygons.
It has reimplemented method
hoverMoveEvent( QGraphicsSceneHoverEvent* event )
that indicates when need to highlight the figure (when mouse crosses the internal line or polygon ).
There are situations when items are drawn one above other, but hover event is accepted only by top item.
I tried to ignore event inside the method but it don't help.
To solve this problem need to reimplement method
QPainterPath QGraphicsItem::shape() const
in the custom item.
This shape should be exactly as a shape of "internal" painted items. Without empty spaces inside the bounding rectangle.

Shadow Effects with QGraphicsRectItem in Qt

I have a QGraphicsRectItem over a scene. I intend to drag and drop this window over the scene. When the rect item reaches the left boundary end I have to show it appearing from the right end. Currently I am using two objects and hiding and showing them by calculating the boundary of scene which involves lot of calculations.
Is there any better way to achieve the same effect using just a single object?
Thank You
You could use a single item that spans the entire scene, and draw the rectangle (or 2 parts of it) in it's paint method.
But then you would lose the optimization of the BSP tree, your item would redraw even if some unrelated area repaints. If this is just 1 item, I guess it would not have much impact.
You would need to implement your own dragging with mousemove event and the like, though this is not much code, you just need to get it right.

flex 4 - depth property not working as expected

I am developing an isometric game.
I have a parent UIComponent (WorldMap). The player can choose MapElement s (game items) and drop them in the playable area WorldMap. This MapElement also is a UIComponent which contains child controls such as Sprite, Image, Label and custom Flex components to hold various information.
Now, I have written a logic to determine which one should appear in back and which one should appear in front in the Isometric area which I am calling idx (index) and I am seeting this value to the depth property of the MapElement.
I have added three components in the order shown in below pic and I have set the depth property each of them as 11077,11168 and 10630. If the depth property worked properly the 3rd item should have gone behind the 1st item but it seems like they are appearing in the order of they have added (default behavior)
If I am not wrong the depth value can be anything
Can some one help me?
I am aware of another solution using swapChildren, swapChildrenAt and and also addChildAt methods (which I don't want to use for my project specific reason) but I need to find out whats wrong with the depth
The problem, as I think, in your WorldMap component which, as you said, is UIComponent. Diving deeper to depth property shows that depth setter launches invalidateLayering method, which is empty in UIComponent and overrides with logic only in Group which is main container for every Flex 4 component. And here's example:
http://www.tink.ws/blog/flex-4-uicomponent-depth/
So, it looks like, you need to use at least Group or SkinnableContainer as your WorldMap in order to achieve depth property to work correctly.
Use UIComponent.addChildAt(child:DisplayObject, index:int). addChildAt adds a child DisplayObject instance to this DisplayObjectContainer instance. The child is added at the index position specified. An index of 0 represents the back (bottom) of the display list for this DisplayObjectContainer object.

highlight item in spark list

I have two spark lists and want to drag items from one list to the other. When im dragging an item and over the other list item, i want the target item to change the background coloer.
Basically instead of showing the black line indicating that I will drop between elements, I want to see the target item highlight.
Thanks in advance.
Edit: Something that would look similar to this drag and drop:
(source: blogspot.com)
I would ask you to point out a UI precedent where this is standard / expected behavior.
When you drag an itemA onto itemB; and itemB is highlighted somehow, it usually means you're dragging into ItemB. But, in this case you are not dragging item from List1 into the item from List2. [I assume at least].
You'd have to override the list code drag and drop features to make this happen.

Resources