How to set QRect in the center of cell in QListVIew with QAbstractItemDelegate's paint?
-
Hello
I have QListVIew and delegate to paint the list view. I paint some text int the center of cell.
so I do it:
@
void Delegate::paint(QPainter *painter, const QStyledOptionViewItem &option, const QModelIndex &index )
{
.
.
.
QRect textRect(option.rect.center(),QSize(option.rect.width(),option.rect.height());paiter->drawText(textRect,text,QTextOption());
@but it starts to paint from the center. how can I center this output?
thank you -
Hi,
Use the Qt::TextWordWrap option
-
[quote author="tokafr" date="1422290145"]what if the text is longer than the width of cell?
[/quote]Either word wrap, or elide the text, or determine that it is too wide, and dynamically find a font size that will fit (within reasonable limits, of course).
-
[quote author="tokafr" date="1422350579"]and how can I set the text in the top but aligned in the center( so topCenter)?
[/quote]Did you have a look at the documentation for the function that I used in my code? It lists all the possible flags you can pass...