Items overlap in QStyledItemDelegate descendant (QListView contents)

  • Good morning.

    I have a bit of a problem writing prototype application. I wrote sample item delegate, implemented its sizeHint and paint methods and it seems like paint ignores any changes to QRect variable used for painting: all the items are aligned to left and overlap. Sample code follows:

    void BlabDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
        QRect irect(option.rect);
        irect.setHeight(54); irect.setWidth(54);
        irect = option.rect;
        irect.setLeft(64); irect.setBottom(option.rect.bottom()-20);
        QTextDocument doc;
    QSize BlabDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const {
        QStyleOptionViewItem iopt = option;
        return QSize(iopt.rect.width(),64);

    Now, qDebug() states that irect actually has correct values (as expected) but QTextDocument looks like inserted under the icon when it should begin with 64px offset from left. Is there something I don't understand about writing paint method? Why does the above code not work? I would appreciate any help since I cannot find the right answer.

    EDIT: When I try to draw text as drawItemText from QStyle (and not use QTextDoc) it is all correct.

    Kind Regards,

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.