Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. What properties determine appearance of text in QSqlRelationalDelegate
Qt 6.11 is out! See what's new in the release blog

What properties determine appearance of text in QSqlRelationalDelegate

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 943 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    drmhkelley
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • eyllanescE Offline
      eyllanescE Offline
      eyllanesc
      wrote on last edited by eyllanesc
      #2

      Override setOptions function: https://code.qt.io/cgit/qt/qtbase.git/tree/src/widgets/itemviews/qitemdelegate.cpp?h=5.15.2#n1222

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        drmhkelley
        wrote on last edited by
        #3

        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?

        eyllanescE 1 Reply Last reply
        0
        • D drmhkelley

          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?

          eyllanescE Offline
          eyllanescE Offline
          eyllanesc
          wrote on last edited by eyllanesc
          #4

          @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

          If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            drmhkelley
            wrote on last edited by
            #5

            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!

            eyllanescE 1 Reply Last reply
            0
            • D drmhkelley

              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!

              eyllanescE Offline
              eyllanescE Offline
              eyllanesc
              wrote on last edited by
              #6

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

              If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved