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:

enter image description here


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -