カスタム デリゲートで QTreeView を使用しており、QAbstractItemModel をサブクラス化しています。子のない項目のグリッド線を表示したいと思います。
最初の表示ではすべて問題ないように見えますが、マウスを項目の上に置くと、下または上の行が消え、項目に戻ると再び表示されます。
これは私の最初の投稿であるため、不要な効果を示すためにいくつかの画像を投稿できないようです。
しかし、カスタムデリゲートまたは 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);
}
使用されるスタイルシートは次のとおりです。
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;}" ;
この動的な動作を取り除き、最初の表示で最初の正しいビューを維持する方法を知っている人はいますか?
ありがとう。