Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. A B C
  2. 1 2 3
  3. 4 5 6
  4.  
  5. class myform(QtGui.QMainWindow):
  6.  
  7. def __init__(self, parent=None):
  8.  
  9. super(myform, self).__init__(parent)
  10.  
  11. self.ui = Ui_mygui()
  12. self.ui.setupUi(self)
  13.  
  14. self.ui.mytablewidget.cellClicked.connect(self.cell_was_clicked)
  15.  
  16. @QtCore.pyqtSlot() # prevents executing following function twice
  17. def cell_was_clicked(self):
  18. row = self.ui.mytablewidget.currentItem().row()
  19. print "row=",row
  20. col = self.ui.mytablewidget.currentItem().column()
  21. print "col=",col
  22. item = self.ui.mytablewidget.horizontalHeaderItem(col).text()
  23. print "item=",item
  24.  
  25. #===================================================================
  26. # given a tablewidget which has a selected row...
  27. # return the column value in the same row which corresponds to a given column name
  28. # fyi: columnname is case sensitive
  29. #===================================================================
  30.  
  31. def getsamerowcell(widget,columnname):
  32.  
  33. row = widget.currentItem().row()
  34. #col = widget.currentItem().column()
  35.  
  36. #loop through headers and find column number for given column name
  37. headercount = widget.columnCount()
  38. for x in range(0,headercount,1):
  39. headertext = widget.horizontalHeaderItem(x).text()
  40. if columnname == headertext:
  41. cell = widget.item(row, x).text() # get cell at row, col
  42. return cell
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement