Hi,

I got _AttributeError: 'NoneType' object has no attribute 'text'_ at line 35 from the code below.

In addition, I tested the index value and it seems to be correct.

Any ideas why i get a NoneType?


Qt Code:
  1. from PySide.QtCore import Slot
  2. from PySide import QtGui, QtCore
  3.  
  4. class Output(object):
  5.  
  6. def __init__(self, physical_type):
  7. ''' '''
  8. self.group_box = QtGui.QGroupBox('Output')
  9. self.layout = QtGui.QVBoxLayout()
  10. self.layout.addWidget(self.group_box, 1)
  11.  
  12. self.tabs = QtGui.QTabWidget()
  13.  
  14. def run(self):
  15. self.tabs.addTab(self.__genTable(), "None")
  16.  
  17. form_layout = QtGui.QFormLayout(self.group_box)
  18. form_layout.addWidget(self.tabs)
  19.  
  20. return self.layout
  21.  
  22. def __genTable(self, rows = 4, columns = 2):
  23. table_view = QtGui.QTableWidget(rows,columns)
  24.  
  25. table_view.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
  26. table_view.setSelectionBehavior( QtGui.QTableView.SelectItems )
  27.  
  28. table_view.horizontalHeader().sectionDoubleClicked.connect(self.changeHorizontalHeader)
  29.  
  30. return table_view
  31.  
  32.  
  33. def changeHorizontalHeader(self, index):
  34. model = self.tabs.currentWidget()
  35. oldHeader = model.horizontalHeaderItem(index).text()
  36. newHeader, ok = QtGui.QInputDialog.getText(QtGui.QInputDialog(),
  37. 'Change header label for column {}'.format(index),
  38. 'Header:',
  39. QtGui.QLineEdit.Normal,
  40. oldHeader)
  41. if ok:
  42. self.tabs.currentWidget().setText(newHeader)
To copy to clipboard, switch view to plain text mode