Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QTableView custom styling



  • Hello, all.

    The concrete desired behavior is: color selective QTableView's rows based on some data provided by the used model e.g. a given role has special value. The possible ways to do it:

    1. Use stylesheet. Here comes the question: how to differentiate which cells are having the desired value for the given role?
    2. Provide the necessary cosmetic data through the model. The problem is that the data variety that could be provided this way is constrained to the background and foreground QBrushes and the text font and alignment. Also, noticed that it is not working 100% of the time and can't tell whether this cosmetic data would be overridden or not by a stylesheet if the latter is used in addition.
    3. Implement 1. by reading the given role's value in a subclassed QStyledItemDelegate and customize the QStyleOptionViewItem instance in the QStyledItemDelegate::paint member function.

    It would be best if 1. is somehow possible. If it is or if there's another more integrated approach aside the delegate one (3.) it would be great. Any suggestions are welcome.


Log in to reply