160行のテーブルを作成しようとしていて、QCheckBox
奇数行ごとに、特に列10に挿入しています。問題は、80行を作成する必要がQCheckBox
あることです(各行に1つずつ、ユーザー)...
QCheckBox
私がしなければならない 9 つのプロジェクト用に80 個のオブジェクトを 1 つずつ作成するのはナンセンスです。
ループでそれを行う方法はありますか?何も考えられず、答えを探しても何も見つかりませんでした。
[...]
# importing PySide
from PySide import QtGui, QtCore
[...]
# Creating a Table
class Table(QtGui.QDialog):
def __init__(self, parent=None):
super(Table, self).__init__(parent)
self.table = QtGui.QTableWidget()
self.table.setRowCount(160)
self.table.setColumnCount(10)
# This is the tricky part:
chkBoxItem = QtGui.QTableWidgetItem()
chkBoxItem.setFlags(QtCore.Qt.ItemIsUserCheckable|QtCore.Qt.ItemIsEnabled)
chkBoxItem.setCheckState(QtCore.Qt.Unchecked)
chkBoxItem2 = QtGui.QTableWidgetItem()
chkBoxItem2.setFlags(QtCore.Qt.ItemIsUserCheckable|QtCore.Qt.ItemIsEnabled)
chkBoxItem2.setCheckState(QtCore.Qt.Unchecked)
chkBoxItem3 = QtGui.QTableWidgetItem()
chkBoxItem3.setFlags(QtCore.Qt.ItemIsUserCheckable|QtCore.Qt.ItemIsEnabled)
chkBoxItem3.setCheckState(QtCore.Qt.Unchecked)
[...]
# Then insert all of them in the Table:
self.table.setItem(0, 10, chkBoxItem)
self.table.setItem(2, 10, chkBoxItem2)
self.table.setItem(4, 10, chkBoxItem3)
self.table.setItem(6, 10, chkBoxItem4)
self.table.setItem(8, 10, chkBoxItem5)
self.table.setItem(10, 10, chkBoxItem6)
self.table.setItem(12, 10, chkBoxItem7)
[...]