When the button is clicked I need the tree-item to turn highlighted (editing mode) (see the image below). Currently I have to double-click the item to set it in to highlighted mode. How to achieve this?
from PyQt4 import QtCore, QtGui
app = QtGui.QApplication([])
class Dialog(QtGui.QDialog):
def __init__(self, parent=None):
super(Dialog, self).__init__(parent)
self.setLayout(QtGui.QVBoxLayout())
tree = QtGui.QTreeWidget()
self.layout().addWidget(tree)
button = QtGui.QPushButton()
button.setText('Add Item')
self.layout().addWidget(button)
button.clicked.connect(self.onClick)
item = QtGui.QTreeWidgetItem()
item.setFlags(item.flags() | QtCore.Qt.ItemIsEditable)
item.setText(0, 'Item number 1')
tree.addTopLevelItem(item)
def onClick(self):
print 'onClick'
dialog=Dialog()
dialog.show()
app.exec_()