[SOLVED] Chidren item selection in a QGraphicsScene.



  • Hi,
    How to make selected items propagate selection to their parent items ? In other words, when i select a children item,
    the parent item will be automatically selected ?

    thanks.



  • hi there :)



  • You can reimplement QGraphicsItem::itemChange in your child item classes, detect the changed selection and change the 'selected' state of your your parent accordingly.



  • Hi, you mean this :

    @
    Label::Label(QGraphicsItem * parent)
    :QGraphicsSimpleTextItem(parent)
    {
    setFlags(QGraphicsItem::ItemIsMovable|
    QGraphicsItem::ItemIsSelectable|
    QGraphicsItem::ItemStacksBehindParent);
    }

    QVariant Label::itemChange (GraphicsItemChange change, const QVariant &value)
    {
    Place * place = qgraphicsitem_cast<Place *>(parentItem());

    if (change == QGraphicsItem::ItemSelectedChange)
      place->setSelected(true);
    

    else
    place->setSelected(false);

    return value;
    }
    @



  • Ok, as you have said, before the site crash, this is the true code :

    @
    QVariant Rectangle::itemChange (GraphicsItemChange change, const QVariant &value)
    {
    if ((change == QGraphicsItem::ItemSelectedHasChanged) && (isSelected()))
    parentItem()->setSelected(true);

    return value;
    }
    @

    it works well, thank you very much. :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.