0

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

4

1 回答 1

1

它从中心开始绘制,因为你告诉它从中心开始对象。您的构造QRect

QRect textRect(option.rect.center(),QSize(option.rect.width(),option.rect.height());

正在呼唤QRect(QPoint topLeft, QSize size)

我认为您想要做的是将矩形的中心移动到您设置为左上角的点,例如:

textRect.moveCenter(option.rect.center());
于 2015-01-26T14:06:45.097 回答