I am using a QTreeView with a custom delegate and i subclassed QAbstractItemModel. I would like to see gridlines for items without children.
At first display, everything’s looks fine but whenever the mouse hovers over an item, the bottom or top line dissappears and reappears when hovering back to the item.
since this is my first post, it seems that i cannot post some images to show the unwanted effect.
But i guess something's wrong with my custom delegate or my stylesheet for the QTreeView :
void ProjetDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if (index.column() > 0 && !index.model()->hasChildren(index))
{
QPen pen;
pen.setColor(QColor(Qt::lightGray));
pen.setWidth(1);
painter->setPen(pen);
painter->drawRect(option.rect);
QStyledItemDelegate::paint(painter,option,index);
}
else QStyledItemDelegate::paint(painter,option,index);
}
The stylesheet used is :
QString treeViewStyle =
"QTreeView { show-decoration-selected: 1; }"
"QTreeView::item:hover { background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 lightgray, stop: 1 white); }"
"QTreeView::item:selected:active { background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 lightgray, stop: 1 lightgray); color: black; }"
"QTreeView::item:selected:!active { background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 lightgray, stop: 1 lightgray); color: black;}" ;
Has anyone an idea of how to get rid of this dynamic behavior and keep the initial correct view at first display ?
Thanks.