Issue
I have added qcheckbox in first cell of qtablewidget now what I want is how to access checkbox and how to get its click event.Basically what I want is on checkbox check row should be selected and on unchecked row should be dis-selected. Here is code:
def add_items(self):
rows = 5
cols = 5
self.tableWidget.setRowCount(5)
self.tableWidget.setColumnCount(5)
for r in range(0, rows):
for c in range(1, cols):
self.qwidget = QtGui.QWidget()
self.checkbox = QtGui.QCheckBox()
self.checkbox.setCheckState(QtCore.Qt.Checked)
qhboxlayout = QtGui.QHBoxLayout(self.qwidget)
qhboxlayout.addWidget(self.checkbox)
qhboxlayout.setAlignment(QtCore.Qt.AlignCenter)
qhboxlayout.setContentsMargins(0, 0, 0, 0)
self.tableWidget.setCellWidget(r, 0, self.qwidget)
item = QTableWidgetItem('note'+str(r))
self.tableWidget.setItem(r, c, item)
print 'done'
Solution
You can use the itemChanged
signal.
from PySide.QtCore import Slot, Qt
from PySide.QtGui import QTableWidgetItem
@Slot(QTableWidgetItem)
def on_tableWidget_itemChanged(self, item):
""" Handles the row's state
:type item: QTableWidgetItem
:parameter item: The changed item
"""
checked = item.checkState() == Qt.Checked
if checked: # the item gets checked
# do stuff here..
else: # the item gets unchecked
# do stuff here
Answered By - noEmbryo
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.