Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Chidren item selection in a QGraphicsScene.
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Chidren item selection in a QGraphicsScene.

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.4k Views 1 Watching
  • 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.
  • I Offline
    I Offline
    issam
    wrote on last edited by
    #1

    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.

    http://www.iissam.com/

    1 Reply Last reply
    0
    • I Offline
      I Offline
      issam
      wrote on last edited by
      #2

      hi there :)

      http://www.iissam.com/

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Asperamanca
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • I Offline
          I Offline
          issam
          wrote on last edited by
          #4

          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;
          }
          @

          http://www.iissam.com/

          1 Reply Last reply
          0
          • I Offline
            I Offline
            issam
            wrote on last edited by
            #5

            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. :)

            http://www.iissam.com/

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