인사 모두가사용자 정의 배경색을 표시하는 Extrend QAbstractListModel?
나는 QCombobox의 배경색을 변경하는 내 자신의 QAbstractListModel을 드리고 있습니다. 이미지에서 보았 듯이 두 가지 문제점이 있습니다. 1) 첫 번째 이미지 스냅 샷에 표시된 것처럼 선택한 항목에 배경색이 표시되지 않습니다. 2) 항목을 선택할 때 배경이 기본 강조 색상 (밝은 파란색)으로 바뀝니다
어쨌든이 두 가지 문제를 해결할 수 있습니까?
여기 내 QAbstractListModel 구현입니다.
RzContourLabelModel::RzContourLabelModel(RzContourLabelContext *contourLabelCtx,int max,QObject *parent) : QAbstractListModel(parent){
contourCtx=contourLabelCtx;
QList contourLabels=contourLabelCtx->getLabels();
for(int i=0;i= colorLabels.size())
return QVariant();
if (role == Qt::DisplayRole){
QString str;
str.setNum(colorLabels.at(index.row()));
return str;
}
if (role == Qt::BackgroundRole)
{
int labelNum=colorLabels.at(index.row());
QColor col= contourCtx->getLabelColor(labelNum);
return col;
}
return QVariant();
}
색상으로 선택하지 않으면 어떻게 시각화 하시겠습니까? 선택을 사용하지 않으려면 setSelectionMode (NoSelection)로 시도해보십시오. QComboBox에서 처리 할 수 있는지 확실하지 않을 수 있습니다. –