如果可能的话,你如何使用 python 来选择一个复选框setVerticalHeaderLabels
?QTableWidget
这将是代码的相关部分......
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.table = QTableWidget()
self.setCentralWidget(self.table)
self.updateTable()
def updateTable(self):
table_rows = range(0,1)
table_cols = range(0,1)
self.table.setRowCount(len(table_rows))
self.table.setColumnCount(len(table_cols))
vertical_label = [self.tableCheckbox() for row in table_rows]
self.table.setVerticalHeaderLabels(vertical_label)
def tableCheckbox(self):
chkBoxItem = QTableWidgetItem()
chkBoxItem.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
chkBoxItem.setCheckState(Qt.Unchecked)
return chkBoxItem
def main():
app = QApplication(sys.argv)
form = MainWindow()
form.show()
app.exec_()
if __name__ == "__main__":
main()
此代码将引发TypeError: QTableWidget.setVerticalHeaderLabels(QStringList): argument 1 has unexpected type 'list'
,因为QTableWidget.setVerticalHeaderLabels()
需要一个字符串列表。