Unsolved QTreeView delegate with background covering only text - howto
-
Hello forum,
I've the classic QTreeView, QStandardItemModel pair. QTreeView has one column.
I'd like that when the user selects an item the background covers only the text, not the entire row,. The result I would like to obtain is shown in the figure. Any kind of suggestion is strongly appreciated, starting from a straightforward one (a qss for example) to a detail within the implementation of a custom delegate. For the moment I've not been able to obtain any result.
Thanks in advance
Giovanni
-
Hi and welcome to devnet,
Can you show what you are actually getting ?
Unless you changed the selection mode, it should only select a cell.
-
SGaist thank you
see attachment
Giovanni
As you can see the blue selection box extends up to the end of the column, also with a surrounding box. I would like a shorter selection box (with or without surrounding rectangle) starting from the beginning of the text, and ending at the end of the text.
Regards
Giovanni -
Then a custom QStyleItemDelegate is what you want. Re-implement the paint method to draw the selection the way you want it.