python - How to select or highlight all items in a QTreeWidget? -
i'm trying build context menu user can right-click on qtreewidget , select items.
you can use qtreeview.selectall()
after setting selection mode allows multiple selection (using qabstractitemview.setselectionmode()
).
example (in pyqt4 use qtgui instead of qtwidgets):
from pyqt5 import qtwidgets app = qtwidgets.qapplication([]) widget = qtwidgets.qtreewidget() widget.addtoplevelitems([qtwidgets.qtreewidgetitem(['dog']), qtwidgets.qtreewidgetitem(['car'])]) widget.setselectionmode(qtwidgets.qabstractitemview.contiguousselection) widget.selectall() widget.show() app.exec_()
and looks like:
Comments
Post a Comment