2012-03-17 4 views
0

Guys QStyledItemDelegate을 기반으로 내 대리자 클래스를 구현했으며 listView에 표시된 텍스트 옆에 확인란이 표시되지 않습니다.내 대리자가 확인란을 표시하지 않습니다.

위임을 사용하기 전에 이러한 체크 박스가 내 listView에 표시되었으므로이 위임 클래스에 문제가 있다는 것을 알고 있습니다.
의견이 있으십니까?

편집

void Display_Delegate::paint(QPainter* painter, 
           const QStyleOptionViewItem& option, 
           const QModelIndex &index) const 
{ 
    QString model_data = index.data().toString(); 
    QFontMetrics metrics = view_->fontMetrics(); 
    int view_width = view_->width(); 
    auto modified_str = adjust_text(metrics,model_data,view_width);//this just makes the string to fit into view, don't bother about it. 
    QStyleOptionViewItemV4 style_option = option; 
    initStyleOption(&style_option,index); 
    QPalette::ColorGroup color_group = style_option.state & QStyle::State_Selected ? QPalette::Active : QPalette::Inactive; 
    if (style_option.state & QStyle::State_Selected) 
    { 
     // painter->setPen(style_option.palette.color(color_group, QPalette::Highlight)); 
     painter->setBackgroundMode(Qt::OpaqueMode); 

     QColor color(148,231,245,100); 
     painter->setBackground(QBrush(color)); 
    } 
    else 
    { 
     painter->setPen(style_option.palette.color(color_group, QPalette::Text)); 
    } 

    painter->drawText(option.rect,modified_str); 
} 
+3

저는 지금 키가 큰 바나나 다이 키를 생각하고 있습니다. 너 자신은 어때? 프로그래밍 문제가있는 사람들이 코드를 게시하는 꿈의 세계에요. –

+0

@KerrekSB 알았어, 내 대리자에 페인트 fnc에 대한 코드를 게시 할게, 괜찮을거야. 모델 및 프록시 모델이 올바르게 구현되었다고 가정 할 수 있습니다. (그들은 dflt 대리인과 함께 올바르게 작동합니다.) – smallB

+0

@KerrekSB 재미있게 +1 할 수있는 방법이 +1은 실제로 내 OP를 편집 한 후에 주어졌지만, 너 생각하니? – smallB

답변

1
Qt::CheckState QStyleOptionViewItemV4::checkState 

If this view item is checkable, i.e., ViewItemFeature::HasCheckIndicator is true, checkState 
is true if the item is checked; otherwise, it is false. 

I에 체크 표시를 갖는 상기 방법이 매우 모호한 참조 알았다. 항목을 "확인 가능"하게하려면이 값을 style option으로 설정하십시오. 따라서 다음과 같이 시도하십시오 :

style_option.ViewItemFeatures = QStyleOptionViewItemV2::HasCheckIndicator; 
관련 문제