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. QTableView focusCell - background color transparent
Forum Update on Monday, May 27th 2025

QTableView focusCell - background color transparent

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 2.9k 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.
  • K Offline
    K Offline
    karlheinzreichel
    wrote on last edited by karlheinzreichel
    #1

    I would like to style the focusCell in a QTableView onyl with a border,
    but without a (maybe styled) background.

    So the background color of a cell with focus shall have the same color
    as the background of the cell (without focus)

    Any suggestions how to proceed ?

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

      Hi and welcome to devnet,

      You should be able to achieve that either using QPalette or QStyleSheet. Another option would be to write a QStyledItemDelegate and reimplement the paint method.

      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
      • K Offline
        K Offline
        karlheinzreichel
        wrote on last edited by
        #3

        Hi thanks for your answer...
        I render already the table cells in the derived QStyledItemDelegate.
        E.g.

        drawControl(QStyle::CE_ItemViewItem, &opt, painter, widget);
        My question is, how to render the selected cell (With which style items QStyle::CE_xxx???).

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

          Can you show the code of your paint function ?

          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
          • K Offline
            K Offline
            karlheinzreichel
            wrote on last edited by
            #5

            So after some hours debugging the QStyle::drawControl code in the library I have found a solution.

            The problem were that we are using an application style sheet.
            So the used style for rendering the tablecell and the content is QStyleSheetStyle.

            If the application is working with QStyleSheetStyle it seem to be not possible to render the content of a tabelcell selection
            without a stylesheet.

            After using another style (the fusion style in this case) the styling of the selected tablecell is possible.

            If somebody is interested in the working code:

            // somewhere in the constructor
            // m_unstyledView is type of QTableView*
            // m_fusionStyle  is type of QStyle*
            
            m_unstyledView = new QTableView; 
            m_fusionStyle = QStyleFactory::create(s3Utf8String("fusion"));
            
            void DataTableDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, 
                                          const QModelIndex& index) const
            {
                QStyleOptionViewItemV4 opt = option;
                initStyleOption(&opt, index);
            
                opt.palette.setColor(QPalette::All, QPalette::Highlight, QColor::fromRgb(255, 255, 0));
                opt.palette.setColor(QPalette::All, QPalette::HighlightedText, QColor::fromRgb(255, 0, 0));
            
                m_unstyledView->setPalette(opt.palette);
            
                m_fusionStyle->drawControl(QStyle::CE_ItemViewItem, &opt, painter, m_unstyledView);
            }
            
            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