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. Items overlap in QStyledItemDelegate descendant (QListView contents)
QtWS25 Last Chance

Items overlap in QStyledItemDelegate descendant (QListView contents)

Scheduled Pinned Locked Moved General and Desktop
qstyleditemdeleqlistviewqtcreatorqt5.4
1 Posts 1 Posters 846 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.
  • artwawA Offline
    artwawA Offline
    artwaw
    wrote on last edited by artwaw
    #1

    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 {
        QStyledItemDelegate::paint(painter,option,index);
        painter->save();
        QRect irect(option.rect);
        irect.setHeight(54); irect.setWidth(54);
        QApplication::style()->drawItemPixmap(painter,irect,0,amodel->get(index.data().toHash()["avatar"].toString()).scaledToHeight(54));
        irect = option.rect;
        irect.setLeft(64); irect.setBottom(option.rect.bottom()-20);
        QTextDocument doc;
        doc.setHtml(index.data().toHash()["text"].toString());
        doc.drawContents(painter,irect);
        painter->restore();
    }
    
    QSize BlabDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const {
        QStyleOptionViewItem iopt = option;
        iopt.rect.setHeight(64);
        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,
    Artur

    For more information please re-read.

    Kind Regards,
    Artur

    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