Important: Please read the Qt Code of Conduct -

qtreeview select single item & column

  • I wonder if someone could help me with the following issue:

    • I have a qtreeview and a QAbstractItemModel. with multiple columns (using pyqt5)
    • When I select a certain column of one index (one "field"), the whole row turns blue and he field additionally gets a thin white line at the bottom.
    • When I access the currentindex.column() function I always get the first column "0" (only if I go and edit a certain column the correct colum-id is available in my setdata function).

    -> I'd like to change the behavior such that really only one "field" (one column of one item) is highlighted or - if this is not possible "at east" get the correct column-id

    I could not find a suitable option in the selectionmodel or selectionmode... There seems to be only options about multi-selection etc. Did I miss something....?

    Thanks a lot in advance!

  • Lifetime Qt Champion


    From what you wrote, QAbstractItemView::SingleSelection and QAbstractItemView::SelectItems comes to mind.

    Hope it helps

  • Thanks a lot for the hints!

    I had tried these without success but your input triggered me to look further in this direction and I discovered something called selectionbehavior.

    In pyqt5 I use:

    Thanks again!

Log in to reply