QListWidget delegate paint problem.
Hi all,
A have just made cistom item delegate, and found some problem on implementing cross-platform paint and sizeHint class methods.
I have Big text in my cell, and I want to adjust Height regarding it,” here is the code of delegate. Your text to link here… [pastebin.com]
As you can see, the sizeHint Method:
- QSize RaspListDeleagte::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
- {
- QSize result;
- //setup fonts
- result.setHeight(fmTF.lineSpacing()+fmTF.leading()*2+4);
- result.setWidth(option.rect.width());
- return result;
- }
And I draw the text by following code:
- painter->setFont(timeFont);
- painter->drawText(option.rect.x()+2,option.rect.y()+fmTF.height(),timeLeft);
I got option.rect.y() plus QFontMetrics height.
It worked good on Mac OS, but it looks ugly on Linux:
As you can see, the big font text with tome shifted (I got shifted option.rect.y()). It mean that every cell of QListWidget has some top marging, ot content margin. But I didn’t find any in QStyleOptionViewItem.
How I can get this margin from Item Delegate ?
4 replies
Regarding this doc [doc.trolltech.com]: I need “Padding” property. But I did not find any direct class methods.
I’ve just checked, And passed such string in initialization of QWidgetList:
- ui->listView->setStyleSheet(" QListWidget { padding: 40px;}");
Unfortunately, with no results.
I have found that custom QItemDelegates can get trickyer than you’d like sometimes…
Perhaps you could work around your issue by not using a delegate, but by using a proxy model. In that model, you could use the item roles for the font, alignment and color to achieve the look you want, and have Qt’s code deal with the actual layout.
Note that this only works if what we are seeing above are separate columns.
You must log in to post a reply. Not a member yet? Register here!




