Python (3+) 및 Qt (5) (Py2.7 및 Qt4 답변도 유용합니다!). 스타일, 위임자, 모델 및 그 밖의 모든 것에 대한 광대 한 문서로 완전히 혼동됩니다.PyQt Tableview 행 배경색 값은 셀 값을 기준으로합니다.
대체 행의 배경을 설정하는 것이 간단하지만 하나의 열이 특정 값 (예 : Archive == True
)과 일치하는 행에 대한 배경을 설정하려고합니다.
대체 행 :
self.plainModel = QSqlQueryModel()
self.create_model()
self.linksTable.setModel(self.plainModel)
self.linksTable.setAlternatingRowColors(True)
self.linksTable.setStyleSheet("alternate-background-color: Lightgrey;background-color: white;")
self.linksTable.resizeColumnsToContents()
나는 through the model 그것을 수행하는 방법을 보여주는 예를 본 적이 있지만 구체적인 예는 단순히 다른 행의 결과를 복제하는 것, 그리고 몇 일 후에 내가 할 수있는 코드를보고 이를 아카이브 열을 검사하는 방법으로 변환하는 방법을 알아보십시오. example에서
추출 : 나는 다른 example using delegates 발견했지만 순간에 주위에 내 머리를 얻을 수
elif role == Qt.BackgroundRole:
if index.row() % 2 == 0:
return QBrush(Qt.yellow)
elif role != Qt.DisplayRole:
return QVariant()
.
특히 어떤 행을 변경할지 선택하는 방법을 이해할 수 없으며 간단한 배경색을 "옵션"으로 적용하는 방법을 이해할 수 없습니다! (QStyleOptionViewItem에 대한 문서를 읽는 것은 토끼 구멍을 내려 보내는 것입니다!).
도와 주시겠습니까?
완벽한 - 내가 후속 질문을 추가했습니다 니가 관심 있으면. 나는 당신이이 질문에 완전히 대답했기 때문에 이것을 토론으로 포함시키지 않았다. https://stackoverflow.com/questions/44121172/pyqt-tableview-background-color-based-on-text-value-rather-than-true-or-false – Alan