Important: Please read the Qt Code of Conduct -

What properties determine appearance of text in QSqlRelationalDelegate

  • Using Qt 5.15.

    I want to change behavior of the displayed table view in the sql/books example.

    Change 1 - Highlight the selected cell differently from the rest of the cells in the row (can use option.state=QStyle::State_HasFocus in the BookDelegate to differente that cell from the other cells in the row that also have QStyle::State_Selected).

    Are there already existing properties that would make that change?

    Change 2 - Change the appearance of the text displayed. For example, bold the text in all cells in the selected row, and bold-italic the text in the selected cell. I can use drawDisplay to modify the displayed text (not my goal but lets me know I've identified and modified the selected row and cell). I had expected to use the QFont in either the QPainter or QStyleOptionViewItem passed to the paint method in the example. But neither seem to have any affect.

    Hence the basic question: What properties determine the appearance of the text? Some property is over-riding my attempted changes, so I'd be better off just changing those.

    Thanks for any suggestions, and in particular pointers to relevant Qt documentation that I must not have found yet.

  • Now I'm really confused.

    1. Your original un-edited response pointed me to the QStyledItemDelegate - which I tried earlier. I gave up because it doesn't understand all the parts that connect the various pieces that ultimately connect the displayed table back to data in the underlying SQL database. What had given me some optimism was that the QSyledItemDelegate appears to understand "by QModelIndex" delegates. The QSqlRelationalDelegate doesn't seem to understand that piece. I couldn't see how either to add SQL pieces to the styled delegates or the by-index pieces to the SQL delegate. That's where I veered off into the drawDisplay rabbit hole.

    2. I don't really understand your re-edited post. It seemed to point to line 1222 in the source for the QItemDelegate widget, which is a "setOptions" function for QItemDelegate. Curiously, I don't find reference anywhere in the Qt documentation for this function. So I naively inserted setOptions into the examples painter function. The compiler accepts that and it doesn't crash, but it also didn't seem to have any effect. If you were trying to imply something different, a bit more info would be very helpful.

    What am I missing?

  • @drmhkelley

    1. There are 2 types of delegates: QItemDelegate and QStyledItemDelegate that use different ways of painting, delete my post because QSqlRelationalDelegate inherits from QItemDelegate so my solution with QStyledItemDelegate is not correct.

    2. It seems strange to me that setOptions () does not appear in the docs, perhaps it is a bug in the docs, but according to the source code, it is seen that the font is established there, so it tells you that you inherit from QSqlRelationalDelegate and override that method

  • Fat-finger problem on my part. I updated the option, but actually passed the original variable to setOptions. When I pass the correct one, I get the desired behavior.

    Thanks a bunch for the pointer to an un-documented feature of the widget!

  • @drmhkelley It would be recommended that you report the bugs of the documentation

Log in to reply