tableView for files: give one type a different colour: why doesn't this work?
using the stardelegate example I made a simple paint function to make a file with extension "001" blue:
Code:
{
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);
}
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.
Re: tableView for files: give one type a different colour: why doesn't this work?
No, this doesn't work because the settings made to the painter are only local.
When the painting is done (as in being performed), the actual style is used and your changes to the painter are lost.
Unless, of course, you do the painting of the text directly in the delegate.
Like the italics, set the color in the option. Then it will work as the style makes use of the option (or should make use of it)
Re: tableView for files: give one type a different colour: why doesn't this work?
thanks, using this now
if (QFileInfo(name).suffix() == "001")
opt.palette.setColor(QPalette::Text,QColor(0, 0, 255, 255) );
and it works