def METHOD_NAME(self, rect, testonly):
    left, top, right, bottom = self.getContentsMargins()
    effective = rect.adjusted(+left, +top, -right, -bottom)
    x = effective.x()
    y = effective.y()
    lineheight = 0
    if not self._items:
        return y + lineheight - rect.y() + bottom
    for item in self._items:
        if item.isEmpty():
            continue
        widget = item.widget()
        if not widget.isVisible():
            continue
        hspace = self.horizontalSpacing()
        if hspace == -1:
            hspace = widget.style().layoutSpacing(
                QSizePolicy.PushButton, QSizePolicy.PushButton, Qt.Horizontal
            )
        vspace = self.verticalSpacing()
        if vspace == -1:
            vspace = widget.style().layoutSpacing(
                QSizePolicy.PushButton, QSizePolicy.PushButton, Qt.Vertical
            )
        nextX = x + item.sizeHint().width() + hspace
        if nextX - hspace > effective.right() and lineheight > 0:
            x = effective.x()
            y = y + lineheight + vspace
            nextX = x + item.sizeHint().width() + hspace
            lineheight = 0
        if not testonly:
            item.setGeometry(QRect(QPoint(x, y), item.sizeHint()))
        x = nextX
        lineheight = max(lineheight, item.sizeHint().height())
    return y + lineheight - rect.y() + bottom