Display current item in bold font, NOT as selected w/ blue background
-
I am subclassing QAbstractListModel for read-only display in a QListView and re-implementing the data() function. My list should display the items in normal font, but the selected item (or current item, since only one selection is allowed) should be in bold font. There should be no blue background, just white background with black text, but bold if it is the current item.
So, how do I do this:
(a) Avoid the default selection display for the current item as white text on a blue background;
(b) Return the appropriate font, but in bold, in my model's data() function.Or is this the wrong way to do it? Do I also need to subclass QListView, for example, and override something there?
Thanks!
-
Hi,
a-b) If you don't want any selection rectangle then you'll have to do it with a QStyledItemDelegate. However note that you are starting to go in the "against the design guidelines" territory.
Since you want to change the font based on the selection, do it also in the QStyledItemDelegate. -
Thanks ... I'll probably reconsider in light of the "design guidelines" thing. But it's nice to know that it's possible, and how to do it.
-
You're welcome !
It's generally a good idea to follow the guidelines for a given platform :)
Happy coding !
-
Samuel, congratulations on becoming the first "Qt Champion"! That's awesome!!
Read about it here:
"Qt Blog about Samuel Gaist":http://blog.qt.digia.com/blog/2014/10/20/say-hello-to-the-first-qt-champion/?utm_source=rss&utm_medium=rss&utm_campaign=say-hello-to-the-first-qt-champion -
Thank you very much :)