qt - How to highlight QTreeWidgetItem text -


enter image description here

when button clicked need tree-item turn highlighted (editing mode) (see image below). have double-click item set in highlighted mode. how achieve this?

enter image description here

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_() 

enter image description here

from pyqt4 import qtcore, qtgui app = qtgui.qapplication([])  class itemdelegate(qtgui.qitemdelegate):     def __init__(self, parent):         qtgui.qitemdelegate.__init__(self, parent)      def createeditor(self, parent, option, index):         if not index: return         line = qtgui.qlineedit(parent)         line.settext('please enter ')         # line.selectall()         line.setselection(0, len(line.text()))         line.setfocus()         return line  class dialog(qtgui.qdialog):     def __init__(self, parent=none):         super(dialog, self).__init__(parent)         self.setlayout(qtgui.qvboxlayout())         self.tree = qtgui.qtreewidget()         self.layout().addwidget(self.tree)         button = qtgui.qpushbutton()         button.settext('add item')         self.layout().addwidget(button)         button.clicked.connect(self.onclick)         self.tree.setcolumncount(3)          delegate=itemdelegate(self)         self.tree.setitemdelegate(delegate)          row in range(5):             rootitem = qtgui.qtreewidgetitem()             self.tree.addtoplevelitem(rootitem)             column in range(3):                 rootitem.settext(column, 'root %s row %s'%(row, column))              child_number in range(2):                 childitem = qtgui.qtreewidgetitem(rootitem)                  col in range(3):                     childitem.settext(col, 'child %s row %s'%(child_number, col))      def onclick(self):         rootitem = qtgui.qtreewidgetitem()         rootitem.settext(0, 'new item')         rootitem.setflags(rootitem.flags() | qtcore.qt.itemiseditable)         self.tree.addtoplevelitem(rootitem)         self.tree.openpersistenteditor(rootitem, 0)         rootitem.setselected(true)   dialog=dialog() dialog.show() app.exec_() 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -