if (option.
state & QStyle::State_Selected) painter->fillRect(option.rect, option.palette.highlight());
if (option.state & QStyle::State_Selected)
painter->fillRect(option.rect, option.palette.highlight());
To copy to clipboard, switch view to plain text mode
And change colour of highlighted text.
void MyDelegate::paint (
const QStyleOptionViewItem& option,
const QModelIndex& index ) const {
QStyleOptionViewItemV4 opt = setOptions(index, option); // or V2 for Qt4.2
//value = index.data(Qt::DisplayRole);
//text = value.toString();
//opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
//drawDisplay(painter, opt, opt.rect, text);
// Change line style around of the cell:
QPen pen
= QPen(Qt
::red,
1, Qt
::DashLine,
Qt::FlatCap, Qt::MiterJoin);
painter->setPen(pen);
painter->drawLine(opt.rect.left(), opt.rect.bottom()+1,
opt.rect.right(), opt.rect.bottom()+1);
painter->drawLine(opt.rect.right()+1, opt.rect.top(),
opt.rect.right()+1, opt.rect.bottom());
// draw rich text:
painter->save();
doc.setHtml( index.data().toString() );
doc.setPageSize( option.rect.size());
painter->setClipRect(option.rect);
painter->translate(option.rect.x(), option.rect.y());
//if (option.state & QStyle::State_Selected)
//painter->setBrush(option.palette.highlightedText());
doc.documentLayout()->draw(painter, context);
//doc.drawContents(painter, option.rect);
painter->restore();
// draw focus:
if (option.
state & QStyle::State_Selected){ QBrush brush
= pal.
highlight();
col.setAlpha(127);
brush.setColor(col);
painter->fillRect(option.rect, brush);
//painter->fillRect(option.rect, option.palette.highlight());
}
}
void MyDelegate::paint (
QPainter *painter,
const QStyleOptionViewItem& option,
const QModelIndex& index ) const {
QString text;
QRect rect;
QVariant value;
QStyleOptionViewItemV4 opt = setOptions(index, option); // or V2 for Qt4.2
//value = index.data(Qt::DisplayRole);
//text = value.toString();
//opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
//drawDisplay(painter, opt, opt.rect, text);
// Change line style around of the cell:
QPen pen = QPen(Qt::red, 1, Qt::DashLine,
Qt::FlatCap, Qt::MiterJoin);
painter->setPen(pen);
painter->drawLine(opt.rect.left(), opt.rect.bottom()+1,
opt.rect.right(), opt.rect.bottom()+1);
painter->drawLine(opt.rect.right()+1, opt.rect.top(),
opt.rect.right()+1, opt.rect.bottom());
// draw rich text:
painter->save();
QTextDocument doc;
doc.setHtml( index.data().toString() );
QAbstractTextDocumentLayout::PaintContext context;
doc.setPageSize( option.rect.size());
painter->setClipRect(option.rect);
painter->translate(option.rect.x(), option.rect.y());
//if (option.state & QStyle::State_Selected)
//painter->setBrush(option.palette.highlightedText());
doc.documentLayout()->draw(painter, context);
//doc.drawContents(painter, option.rect);
painter->restore();
// draw focus:
if (option.state & QStyle::State_Selected){
QPalette pal=option.palette;
QBrush brush = pal.highlight();
QColor col = brush.color();
col.setAlpha(127);
brush.setColor(col);
painter->fillRect(option.rect, brush);
//painter->fillRect(option.rect, option.palette.highlight());
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks