qt_gotcha
3rd September 2010, 17:35
using the stardelegate example I made a simple paint function to make a file with extension "001" blue:
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);
}
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.
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);
}
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.