Reputation: 119
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
Upvotes: 0
Views: 1532
Reputation: 5377
It's starting to draw from the centre, because you're telling it to start the object from the centre. Your construction of the QRect
:
QRect textRect(option.rect.center(),QSize(option.rect.width(),option.rect.height());
Is calling QRect(QPoint topLeft, QSize size)
.
What I think you want to do, is move the centre of your rectangle to the point that you've set as its top-left, something like:
textRect.moveCenter(option.rect.center());
Upvotes: 1