Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QGraphicsPathItem is not getting highlighted
Qt 6.12 LTS is out! See what's new in the release blog

QGraphicsPathItem is not getting highlighted

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 479 Views
  • 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.
  • T Offline
    T Offline
    tushu
    wrote on last edited by
    #1

    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 :

    1. When I search symbol, except symbol's arc, all the part gets highlighted.
    2. When I zoom in, arc of symbol gets disappear.

    Here are screen shots :

    Original symbol
    sym1.PNG

    After search, whole symbol should get highlight, but here arc is not getting highlighted.
    sym2.PNG

    After zoom in, arc is getting disappear
    sym3.PNG

    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 QGraphicsEllipseItem
    
    void 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.

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jameswalter
      wrote on last edited by
      #2

      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.

      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
      • Unsolved