QTableView に色を付けるには助けが必要です。@rainerは、テーブルを初期化するときに色を付けるのを手伝ってくれましたが、現在、データを含むテーブルが既にあります(ただし、色はありません//データはテーブルで開かれたcsvです)。クリックしたときにボタンを作成したい-2(データ)の行がある場合のように、いくつかの行でテーブルビューに色を付けます.--ボタンとテーブルがあります。このボタンは、csv データをテーブルビューにロードします。このテーブルの行に色を付ける新しいボタンが必要です。(ただし、たとえば、-2 のデータを持つ行のみに色を付けます) いくつかのコード:
self.fileName = (_fromUtf8('tweets.csv'))
self.tableView = QTableView(self.tabSentimento)
self.tableView.setGeometry(QRect(550,10,510,700))
self.tableView.setObjectName(_fromUtf8("TabelaSentimento"))
self.tableView.setModel(self.model)
self.tableView.horizontalHeader().setStretchLastSection(True)
self.pushButtonLoad = QPushButton(self.tabSentimento)
self.pushButtonLoad.setGeometry(QRect(550,720,130,30))
self.pushButtonLoad.setObjectName(_fromUtf8("buttonLoadCSV"))
self.pushButtonLoad.setText(QApplication.translate("Form", "Process!", None, QApplication.UnicodeUTF8))
self.pushButtonLoad.setStyleSheet('color:red;background-color:rgb(255, 255, 153);border:1px solid purple;')
self.pushButtonLoad.clicked.connect(self.on_pushButtonLoad_clicked)
def loadCsv(self, fileName):
with open(fileName, "rb") as fileInput:
for row in csv.reader(fileInput):
items = [
QStandardItem(field)
for field in row
]
self.model.appendRow(items)
def on_pushButtonLoad_clicked(self):
print self.fileName
self.loadCsv(self.fileName)