Important: Please read the 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)
        if (index < 0 || index >= d->engine.itemCount()) {
            qWarning("QGraphicsLinearLayout::removeAt: invalid index %d", index);
        if (QGridLayoutItem *gridItem = d->engine.itemAt(index)) {
            if (QGraphicsLayoutItem *layoutItem = gridItem->layoutItem())
            delete gridItem;

  • Lifetime Qt Champion

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

Log in to reply