사용자 지정 대리자가있는 QTreeView를 사용 중이고 QAbstractItemModel을 서브 클래 싱했습니다. 자녀가없는 항목에 눈금 선을 표시하고 싶습니다.QTreeView로 눈금 선 표시
처음에는 모든 것이 잘 보이지만 항목 위로 마우스를 가져 가면 항목 위로 마우스를 가져 가면 아래쪽 또는 위쪽 줄이 사라지고 다시 나타납니다.
내 첫 번째 게시물이기 때문에, 나는 원치 않는 효과를 보여주기 위해 일부 이미지를 게시 할 수없는 것으로 보입니다.
하지만 난 내 사용자 지정 위임 또는 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;}" ;
이 제거하는 방법에 대한 아이디어를 사람을 가지고 동적 행동과 첫 번째 디스플레이에서 초기 올바른보기를 유지?
감사합니다.
답장을 보내 주셔서 감사합니다. QStyledItemDelegate의 기본 클래스에서 스타일 시트와 페인트 메서드를 사용하는 대체 솔루션을 찾았지만 정확히 처음에는 원하는 바가 아닙니다. "QTreeView :: item :! has-children {border : 0.5px; border-style : 솔리드; border-color : lightgray;} " ' – IbliSS
나는 여전히 해결 방법이나 해킹과 같이 고려할 것입니다. 어쨌든 ... 멋진 – Yash