Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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



  • 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();
        }
    }
    

  • Lifetime Qt Champion



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


Log in to reply