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. Creating a custom QGraphicsLayout - not quite understanding existing subclasses...
Forum Update on Monday, May 27th 2025

Creating a custom QGraphicsLayout - not quite understanding existing subclasses...

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 191 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.
  • A Offline
    A Offline
    Asperamanca
    wrote on last edited by
    #1

    I want to create a custom subclass of QGraphicsLayout. In order to do so properly, I have taken a closer look at the most similar Qt-delivered implementation: QGraphicsLinearLayout.

    What confuses me: For the function removeAt, the documentation on how it is supposed to behave seems to deviate from the code. Am I seeing this wrong? (Take a look at the 'delete' line towards the end of the method)

    /*!
        Removes the item at \a index without destroying it. Ownership of the item
        is transferred to the caller.
    
        \sa removeItem(), insertItem()
    */
    void QGraphicsLinearLayout::removeAt(int index)
    {
        Q_D(QGraphicsLinearLayout);
        if (index < 0 || index >= d->engine.itemCount()) {
            qWarning("QGraphicsLinearLayout::removeAt: invalid index %d", index);
            return;
        }
        if (QGridLayoutItem *gridItem = d->engine.itemAt(index)) {
            if (QGraphicsLayoutItem *layoutItem = gridItem->layoutItem())
                layoutItem->setParentLayoutItem(0);
            d->removeGridItem(gridItem);
            delete gridItem;
            invalidate();
        }
    }
    
    jsulmJ A 2 Replies Last reply
    0
    • A Asperamanca

      I want to create a custom subclass of QGraphicsLayout. In order to do so properly, I have taken a closer look at the most similar Qt-delivered implementation: QGraphicsLinearLayout.

      What confuses me: For the function removeAt, the documentation on how it is supposed to behave seems to deviate from the code. Am I seeing this wrong? (Take a look at the 'delete' line towards the end of the method)

      /*!
          Removes the item at \a index without destroying it. Ownership of the item
          is transferred to the caller.
      
          \sa removeItem(), insertItem()
      */
      void QGraphicsLinearLayout::removeAt(int index)
      {
          Q_D(QGraphicsLinearLayout);
          if (index < 0 || index >= d->engine.itemCount()) {
              qWarning("QGraphicsLinearLayout::removeAt: invalid index %d", index);
              return;
          }
          if (QGridLayoutItem *gridItem = d->engine.itemAt(index)) {
              if (QGraphicsLayoutItem *layoutItem = gridItem->layoutItem())
                  layoutItem->setParentLayoutItem(0);
              d->removeGridItem(gridItem);
              delete gridItem;
              invalidate();
          }
      }
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @asperamanca said in Creating a custom QGraphicsLayout - not quite understanding existing subclasses...:

      seems to deviate from the code

      In what way?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Asperamanca

        I want to create a custom subclass of QGraphicsLayout. In order to do so properly, I have taken a closer look at the most similar Qt-delivered implementation: QGraphicsLinearLayout.

        What confuses me: For the function removeAt, the documentation on how it is supposed to behave seems to deviate from the code. Am I seeing this wrong? (Take a look at the 'delete' line towards the end of the method)

        /*!
            Removes the item at \a index without destroying it. Ownership of the item
            is transferred to the caller.
        
            \sa removeItem(), insertItem()
        */
        void QGraphicsLinearLayout::removeAt(int index)
        {
            Q_D(QGraphicsLinearLayout);
            if (index < 0 || index >= d->engine.itemCount()) {
                qWarning("QGraphicsLinearLayout::removeAt: invalid index %d", index);
                return;
            }
            if (QGridLayoutItem *gridItem = d->engine.itemAt(index)) {
                if (QGraphicsLayoutItem *layoutItem = gridItem->layoutItem())
                    layoutItem->setParentLayoutItem(0);
                d->removeGridItem(gridItem);
                delete gridItem;
                invalidate();
            }
        }
        
        A Offline
        A Offline
        Asperamanca
        wrote on last edited by
        #3

        I misread the code: Not the QGraphicsLayoutItem is destroyed, but a wrapper QGridLayoutItem class.

        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