In table view, model, when you click on cell, what method do you know about cell row and column?
Version:PyQt : 4.11.4
Python : 3.5.3
These are my setting of table view, model.
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ntableView = QtGui.QTableView()
self.nlayout = QtGui.QVBoxLayout()
self.nmodel = QtGui.QStandardItemModel()
self.ntableView.setModel(self.nmodel)
self.nlayout.addWidget(self.ntableView)
self.setLayout(self.nlayout)
self.func_mappingSignal()
def func_mappingSignal(self):
self.ntableView.clicked.connect(self.func_test)
def func_test(self, item):
# http://www.python-forum.org/viewtopic.php?f=11&t=16817
cellContent = item.data()
print(cellContent) # test
sf = "You clicked on {}".format(cellContent)
print(sf)
If you want to get coordinates of clicked cell, you can use parameter of clicked
signal handler, like you have called it item
(it's QModelIndex
in this case)
def func_test(self, item):
and get item.column(), item.row()
values.
like
sf = "You clicked on {0}x{1}".format(item.column(), item.row())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With