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. How to prevent painting bottom border for some cells in QTableView

How to prevent painting bottom border for some cells in QTableView

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 721 Views 2 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.
  • P Offline
    P Offline
    patrickkidd
    wrote on last edited by
    #1

    I have one column in a QTableView in which I do not want to have any grid lines painted. Is this possible?

    Thanks

    https://alaskafamilysystems.com/

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

      Hi
      As far as i know, you can only default disable whole grid
      setShowGrid(false);
      However, you can use a Delegate and paint the cells borders yourself and
      then that way avoid painting for some.

      https://stackoverflow.com/questions/7262318/how-do-i-assign-a-border-to-a-specific-qtablewidgetitem-or-a-row-in-a-qtablewidge/7264248#7264248

      class MyDelegate : public QItemDelegate {
        public:
          MyDelegate( QObject *parent ) : QItemDelegate( parent ) { }
          void paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const {
            QItemDelegate::paint( painter, option, index );
            if( /* some condition */ ) {
               painter->setPen( Qt::red );
               painter->drawRect( option.rect );
            }
          }
      }
      
      P 1 Reply Last reply
      2
      • mrjjM mrjj

        Hi
        As far as i know, you can only default disable whole grid
        setShowGrid(false);
        However, you can use a Delegate and paint the cells borders yourself and
        then that way avoid painting for some.

        https://stackoverflow.com/questions/7262318/how-do-i-assign-a-border-to-a-specific-qtablewidgetitem-or-a-row-in-a-qtablewidge/7264248#7264248

        class MyDelegate : public QItemDelegate {
          public:
            MyDelegate( QObject *parent ) : QItemDelegate( parent ) { }
            void paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const {
              QItemDelegate::paint( painter, option, index );
              if( /* some condition */ ) {
                 painter->setPen( Qt::red );
                 painter->drawRect( option.rect );
              }
            }
        }
        
        P Offline
        P Offline
        patrickkidd
        wrote on last edited by
        #3

        @mrjj That certainly works, thanks.

        https://alaskafamilysystems.com/

        1 Reply Last reply
        1

        • Login

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