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 draw border
QtWS25 Last Chance

Qtableview draw border

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 901 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.
  • N Offline
    N Offline
    n-2204
    wrote on last edited by
    #1

    Is it possible to draw border in a qtableview row/item ? not for complete table only to row/cell
    using stylesheet it will be applicable for table
    please suggest

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Use a custom item delegate and override the paint() to draw a border around the cell.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      N 1 Reply Last reply
      2
      • Christian EhrlicherC Christian Ehrlicher

        Use a custom item delegate and override the paint() to draw a border around the cell.

        N Offline
        N Offline
        n-2204
        wrote on last edited by VRonin
        #3

        ok something like this

        void CustomDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
        {
            QStyledItemDelegate::paint(painter, option, index);
        
            QPen oldPen = painter->pen();
            painter->setPen(_gridPen);
        
            // paint vertical lines
            painter->drawLine(option.rect.topRight(), option.rect.bottomRight());
            // paint horizontal lines 
            if (index.column()!=1) //<-- check if column need horizontal grid lines
                painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
        
            painter->setPen(oldPen);
        }
        

        And in qtableview row how can i set font for a particular row
        as for table i can use ui.tableView->setFont(QFont("Times", 10));
        but only for row how to do ?

        1 Reply Last reply
        0
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @n-2204 said in Qtableview draw border:

          And in qtableview row how can i set font for a particular row

          Similar to your painting. Don't forget to override https://doc.qt.io/qt-5/qstyleditemdelegate.html#sizeHint

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          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