wirasto
22nd January 2010, 16:51
I just make a my custom style. In my QStyle, I fillrec itemviewrow on drawPrimitive function. Oh, yes I use this style just for my QTreeView..
model=new MyModel();
ui->treeView->setModel(model);
ui->treeView->setStyle(new TreeStyle());
In MyModel I tried set backgroud color for a row with Qt::BackgroundColorRole. But I don't understand why not work. If I remove setStyle from my treeView, Qt::BackgroundColorRole will work..
//TReeStyle COde
void TreeStyle::drawPrimitive(PrimitiveElement element, const QStyleOption* option,
QPainter* painter, const QWidget* widget) const
{
if (element == PE_PanelItemViewRow || element == PE_PanelItemViewItem)
{
painter->fillRect(option->rect, option->palette.highlight());
}
.......................
.......................
//MyModel Code
if (role == Qt::BackgroundColorRole)
{
.......................
.......................
return qVariantFromValue(QColor(255, 186, 186));
}
This is normal ? I can't use booth QStyle and Model for QTreeView ?
model=new MyModel();
ui->treeView->setModel(model);
ui->treeView->setStyle(new TreeStyle());
In MyModel I tried set backgroud color for a row with Qt::BackgroundColorRole. But I don't understand why not work. If I remove setStyle from my treeView, Qt::BackgroundColorRole will work..
//TReeStyle COde
void TreeStyle::drawPrimitive(PrimitiveElement element, const QStyleOption* option,
QPainter* painter, const QWidget* widget) const
{
if (element == PE_PanelItemViewRow || element == PE_PanelItemViewItem)
{
painter->fillRect(option->rect, option->palette.highlight());
}
.......................
.......................
//MyModel Code
if (role == Qt::BackgroundColorRole)
{
.......................
.......................
return qVariantFromValue(QColor(255, 186, 186));
}
This is normal ? I can't use booth QStyle and Model for QTreeView ?