QGraphicsPathItem is not getting highlighted
-
I have a QGraphicsView which has many symbols ( AND, OR, NOT etc ) made of various QGraphicsItem like , QGraphicsLineItem ( for straight line ), QGraphicsPathItem ( for curve ) , QGraphicsEllipseItem ( for circle )
All these QGraphicsItem, I have bundled in QGraphicsItemGroup.
I have a Search feature, which takes name of symbol and search it in view and once found highlihgt that symbol.
I have a zoom in feature, which zoomed in the view with pre defined scale.Issue :
- When I search symbol, except symbol's arc, all the part gets highlighted.
- When I zoom in, arc of symbol gets disappear.
Here are screen shots :
Original symbol
After search, whole symbol should get highlight, but here arc is not getting highlighted.
After zoom in, arc is getting disappear
Code :
In searchSymbol feature, there is a function to highlight symbol.class myGroup : public QGraphicsItemGroup class myArc: public QGraphicsPathItem class myLine: public QGraphicsLineItem class myEllipse: public QGraphicsEllipseItemvoid myViewer::HighLightSymbol(QGraphicsItemGroup* symAddress) { QList<QGraphicsItem*> childItems = symAddress->childItems(); QPen mPen(Qt::SolidLine); mPen.setWidth(2); foreach (QGraphicsItem* chItem, childItems) { //if (myArc* poly = dynamic_cast<myArc*>(chItem)) if (QGraphicsPathItem* poly = dynamic_cast<QGraphicsPathItem*>(chItem)) { qDebug()<<"HighLightSymbol Arc ----> "<<poly; poly->setPen(mPen); } else { if (myLine* line = dynamic_cast<myLine*>(chItem)) { qDebug()<<"HighLightSymbol line ----> "<<line; line->setPen(mPen); } else { if (myEllipse* ell = dynamic_cast<myEllipse*>(chItem)) ell->setPen(mPen); } } } }In above code, I have printed all the QGraphicsPathItem* poly and myLine* line. There address is exactly same as when symbol has created.
I know it is very difficult to guess issue from limited code. But still, if anyone has any suggestion, please provide it so atleast I will get some idea to debug.
-
Connect a slot to the QGraphicsScene::selectionChanged() signal. In the slot, retrieve the QList of selected items QGraphicsScene::selectedItems(). Use that list to change the colors. If you keep a copy of the previous selections (initially empty), then you can change the colors only for the items that are not common to the old and new selection lists for better efficiency.