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. Treeview with grid lines
Forum Updated to NodeBB v4.3 + New Features

Treeview with grid lines

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 5.9k 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.
  • P Offline
    P Offline
    phamtv
    wrote on last edited by
    #1

    I have a custom QSortFilterProxyModel with its source model set to the QFileSystemModel displayed via a QTreeView. Is it possible for the QTreeView to show gridlines vertically and horizontally? If so, can you provide an example. Thanks!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Sam
      wrote on last edited by
      #2

      Hi
      You can create a delegate for example :-

      .h

      @class TreeViewDelegate : public QStyledItemDelegate
      {
      Q_OBJECT
      public:
      explicit TreeViewDelegate(QObject *parent = 0);
      void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;

      };@

      .cpp

      @TreeViewDelegate::TreeViewDelegate(QObject *parent) :
      QStyledItemDelegate(parent)
      {

      }

      void TreeViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
      {
      QStyledItemDelegate::paint(painter,option,index);

      QPen pen;
      pen.setWidth(1);
      painter->setPen(pen);
      painter->drawRect(option.rect);
      

      }@

      then you can set the the delegate to the treeView

      @ui->treeView->setItemDelagate(treeDelegate);@

      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