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. [SOLVED]: QTableView, highlight a part of a row
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]: QTableView, highlight a part of a row

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 2.4k Views 1 Watching
  • 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.
  • _ Offline
    _ Offline
    _Mark_
    wrote on last edited by
    #1

    Hello,
    I have a QTableView with the selection mode set to "row". I want to highlight only a part of the whole row, actually. Say, from column 2 to the end.

    I think I must subclass QTableView and reimplement the paint event. But I don't know how to fill the rectangle of the desired cells. Perhaps is there a more convenient way?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      archqt
      wrote on last edited by
      #2

      Hi,
      you want to Highlight when you select a row only ? else for the QAbstractTableModel the data is done for that (display, color, data...).
      Sincerely

      1 Reply Last reply
      0
      • _ Offline
        _ Offline
        _Mark_
        wrote on last edited by
        #3

        Yes, I'm talking when the user select a row (i.e. click on a cell of a row).
        Otherwise I would use the Qt::background role in the model.

        The final goal is to prevent the highlight color to override the background of the first cell.
        I mean, I want the first column maintains its own background even when the row is selected.

        1 Reply Last reply
        0
        • _ Offline
          _ Offline
          _Mark_
          wrote on last edited by
          #4

          I tried removing the Qt::ItemIsSelectable from the first cell. The appearance is exactly as I want, but now the delegate won't open anymore...

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            You can implement you own QStyledItemDelegate and avoid drawing the selection rectangle.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • _ Offline
              _ Offline
              _Mark_
              wrote on last edited by
              #6

              Done. Thank you.

              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