在第二个临时文本中,第一列中包含第10行,第2列,包含复选框
按下名为Copy(仅打印)的按钮后,我需要在cloumn 1中检查所有checkBox的状态
.................................................. ...........................................
import PySide.QtCore as QtCore
import PySide.QtGui as QtGui
class chck( QtGui.QCheckBox ):
def __init__( self, *args, **kwargs ):
super( chck, self ).__init__( *args, **kwargs)
class TestTable( QtGui.QDialog ):
def __init__( self, parent=None ):
QtGui.QDialog.__init__( self, parent )
self.resize( 300, 500 )
self.myTable = QtGui.QTableWidget()
self.myTable.setColumnCount( 2 )
self.myTable.setRowCount( 10 )
self.copyButton = QtGui.QPushButton(self.tr("Copy"))
self.copyButton.clicked.connect(self.copy)
for i in range( 0, self.myTable.rowCount() ):
ok = chck( '' +str(i+1))
self.myTable.setCellWidget( i,0,ok) # set check box
item = QtGui.QTableWidgetItem("text" + str(i+1))# set tmp text
self.myTable.setItem(i,1,item)
buttonLayout = QtGui.QHBoxLayout()
buttonLayout.addStretch(1)
buttonLayout.addWidget(self.copyButton)
layout = QtGui.QVBoxLayout()
layout.addWidget(self.myTable)
layout.addLayout(buttonLayout)
self.setLayout(layout)
def copy( self ):
for i in range( 0, self.myTable.rowCount() ):
print "Check box " + str(i+1) + " is :" # print status QCheckBox if is on or off
tableView = TestTable()
tableView.show()
答案 0 :(得分:0)
获取cellWidget复选框,然后使用isChecked:
def copy(self):
for i in range(0, self.myTable.rowCount()):
checkbox = self.myTable.cellWidget(i, 0)
print "Check box " + str(i+1) + " is :",
print 'checked' if checkbox.isChecked() else 'not checked'