{
painter
->setRenderHint
(QPainter::TextAntialiasing);
//painter->setPen(Qt::NoPen);
if (option.
state == QStyle::State_Selected) painter->setBrush(option.palette.highlight());
else
painter
->setBrush
(QBrush(Qt
::white));
rosterItem *item = static_cast<rosterItem*>(index.internalPointer());
int width=Qxygen->viewWidth(), height;
if(item->data(1).isEmpty())
{
height=fmetrics.height();
}
else
{
height=fmetrics.height()+fmetrics.height()*qRound(fmetrics.width(item->data(1))/width);
if(fmetrics.width(item->data(1))%width>0)
height+=14;
}
printf("Width: %d Height:%d\n", width, height);
QImage img
=Qxygen
->model
()->data
(index, Qt
::DecorationRole).
value<QImage>
();
QRect irect
(option.
rect.
x(), option.
rect.
y(), img.
width(), img.
height());
QRect rect
(option.
rect.
x()+img.
width()+2, option.
rect.
y(), width
-img.
width()-2, height
);
opt.setAlignment(Qt::AlignTop|Qt::AlignLeft);
painter->drawImage(irect, img);
// painter->drawText(rect, Qxygen->model()->data(index, Qt::DisplayRole).toString(), opt);
painter->drawText(rect, Qt::TextWordWrap|Qt::AlignLeft|Qt::AlignTop, Qxygen->model()->data(index, Qt::DisplayRole).toString());
// painter->drawText(rect,Qt::TextWordWrap,elidedText(static_cast<const QFontMetrics&>(Qxygen->roster()->fontMetrics()), rect.width(),Qt::ElideRight,Qxygen->model()->data(index, Qt::DisplayRole).toString()));
}
void rosterDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
painter->setRenderHint(QPainter::TextAntialiasing);
//painter->setPen(Qt::NoPen);
if (option.state == QStyle::State_Selected)
painter->setBrush(option.palette.highlight());
else
painter->setBrush(QBrush(Qt::white));
QTextOption textOption;
textOption.setWrapMode(QTextOption::WordWrap);
rosterItem *item = static_cast<rosterItem*>(index.internalPointer());
int width=Qxygen->viewWidth(), height;
QFontMetrics fmetrics=Qxygen->fontMetrics();
if(item->data(1).isEmpty())
{
height=fmetrics.height();
}
else
{
height=fmetrics.height()+fmetrics.height()*qRound(fmetrics.width(item->data(1))/width);
if(fmetrics.width(item->data(1))%width>0)
height+=14;
}
printf("Width: %d Height:%d\n", width, height);
QImage img=Qxygen->model()->data(index, Qt::DecorationRole).value<QImage>();
QRect irect(option.rect.x(), option.rect.y(), img.width(), img.height());
QRect rect(option.rect.x()+img.width()+2, option.rect.y(), width-img.width()-2, height);
QTextOption opt;
opt.setWrapMode(QTextOption::WordWrap);
opt.setAlignment(Qt::AlignTop|Qt::AlignLeft);
painter->drawImage(irect, img);
// painter->drawText(rect, Qxygen->model()->data(index, Qt::DisplayRole).toString(), opt);
painter->drawText(rect, Qt::TextWordWrap|Qt::AlignLeft|Qt::AlignTop, Qxygen->model()->data(index, Qt::DisplayRole).toString());
// painter->drawText(rect,Qt::TextWordWrap,elidedText(static_cast<const QFontMetrics&>(Qxygen->roster()->fontMetrics()), rect.width(),Qt::ElideRight,Qxygen->model()->data(index, Qt::DisplayRole).toString()));
}
To copy to clipboard, switch view to plain text mode
Bookmarks