using the stardelegate example I made a simple paint function to make a file with extension "001" blue:
{
if (index.column() == 0)
{
QString name
= index.
model()->data
(index, Qt
::DisplayRole).
toString();
{
painter
->setPen
(QColor(0,
0,
255,
255));
QFont f
= painter
->font
();
painter->setFont(f);
opt.font.setItalic(true);
}
}
QStyledItemDelegate::paint(painter, opt, index);
}
void StarDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
QStyleOptionViewItem opt = option;
if (index.column() == 0)
{
QString name = index.model()->data(index, Qt::DisplayRole).toString();
if (QFileInfo(name).suffix() == "001")
{
painter->setPen(QColor(0, 0, 255, 255));
QFont f = painter->font();
painter->setFont(f);
opt.font.setItalic(true);
}
}
QStyledItemDelegate::paint(painter, opt, index);
}
To copy to clipboard, switch view to plain text mode
The files with 001 are displayed in italics but not in blue. So the selection and adapting opt works, but setPen doesn't. Why not? thanks.
Bookmarks