How can I get the selected item in tableview pyqt4

How can I get or print a clicked item in a table? here is an example code

def connectSlots(self): 
    # this does not work .. 
    QtCore.QObject.connect(self.tableView, QtCore.SIGNAL("clicked(const QModelIndex&"), self._onClick) 
    QtCore.QObject.connect(self.tableView, QtCore.SIGNAL("clicked(QModelIndex"), self._onClick) 

def _onClick(self, *args): 
    print "_onClick", args 
+3
source share
1 answer

I found the answer :)

def connectSlots(self):
    QtCore.QObject.connect(self.ui.tableView, QtCore.SIGNAL("clicked(QModelIndex)"), self.cellClicked)


def cellClicked( self, qmodelindex ):
    self.item = qmodelindex.data(QtCore.Qt.DisplayRole).toString()
    print self.item

this will allow you to get and print the elements that were clicked in qtableview just complicated the search for examples

thanks Stephen ..

+8
source

All Articles