Unselect in QTreeWidget PyQt4

137 views Asked by At

I have the following code:

from PyQt4 import QtGui, QtCore
import sys

class Example(QtGui.QWidget):
    def __init__(self):
        super(Example, self).__init__()
        self.initUI()

    def initUI(self):
        self.mytree = QtGui.QTreeWidget()
        self.label = QtGui.QLabel()
        self.label.setText("Browser")

        self.mylayout = QtGui.QFormLayout()
        self.setLayout(self.mylayout)

        self.mylayout.setWidget(0, QtGui.QFormLayout.LabelRole, self.label)
        self.mylayout.setWidget(0, QtGui.QFormLayout.FieldRole, self.mytree)

        self.first = QtGui.QTreeWidgetItem(self.mytree)
        self.first.setText(0, 'first')
        self.second = QtGui.QTreeWidgetItem(self.mytree)
        self.second.setText(0, 'second')
        self.third = QtGui.QTreeWidgetItem(self.mytree)
        self.third.setText(0, 'third')

        self.mytree.setHeaderHidden(1)
        self.show()

def main():
    app = QtGui.QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()

I just create a window with QTreeWidget. Initially no items are selected. If I select an item (first, second or third) then I cannot remove this selection. Any ideas how can I remove this selection (return to the initial state) once I select something? Ideally when I click on blank space it should remove a selection.

enter image description here

0

There are 0 answers