문제 : 나는 테이블에 마우스로 행을 선택하면, 는 그림 1이 # 2 그림 된다 - 당신이 볼 수 있듯이, 내 모든 그린 아이콘이 사라지고있다!QTreeWidget에서 델리게이트로 ico + 텍스트 데이터를 그리는 방법 (행 선택시)?
질문 : 누구든지이 문제를 도와 줄 수 있습니까? 어쩌면 어떤 사람들은 이미 이런 딜레마에 빠지면 그것을 해결할 수 있을까요? ks스!
그림 # 1
그림 # 2
추가 : 나는 숨겨진 일부 데이터가있는 테이블 (로 QTreeWidget
을 사용하고 있습니다 루트). QTreeWidget
개체하려면 열 위임을 추가합니다 (1, 2 및 3 열은 있지만 4 열은 아닙니다). 모든 대표자 (QStyledItemDelegate
클래스를 기반으로 함)에서는 paint()
메서드를 다시 구현하여 특정 아이콘이나 텍스트 데이터를 그립니다. 여기
void ChainTableDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
QStyleOptionViewItem op = option;
op.state &= ~QStyle::State_HasFocus;
if(index.column() == TreeView::ePosChain)
{
QModelIndex parentIndex = index.parent();
if(!childCount(index) && !parentIndex.isValid())
{
QStyledItemDelegate::paint(painter, op, index);
return;
}
if(!parentIndex.isValid())
{
// top
painter->drawPixmap(pos(op, topActivePix_), topActivePix_);
}
else
{
int row = index.row();
if(row != childCount(parentIndex) - 1)
{
// middle
painter->drawPixmap(pos(op, middleActivePix_), middleActivePix_);
}
else
{
// bottom
painter->drawPixmap(pos(op, bottomActivePix_), bottomActivePix_);
}
}
}
QStyledItemDelegate::paint(painter, op, index);
}
한 아이콘을 덮어 * SO *거야! :-) Thnks 많이. 멍청한 실수... – mosg