Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QTreeView delegate with background covering only text - howto
gbettega last edited by aha_1980
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
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.
gbettega last edited by gbettega
SGaist thank you
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.
Then a custom QStyleItemDelegate is what you want. Re-implement the paint method to draw the selection the way you want it.