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 create grid line in QTreewidget
Forum Updated to NodeBB v4.3 + New Features

How to create grid line in QTreewidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 2.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.
  • ManiRonM Offline
    ManiRonM Offline
    ManiRon
    wrote on last edited by ManiRon
    #1

    I am trying to implement grid lines between the columns in a QTreeWidget, whether it is possible . Help me with this ?

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

      Hi
      Do you mean like this
      alt text

      ManiRonM 2 Replies Last reply
      0
      • mrjjM mrjj

        Hi
        Do you mean like this
        alt text

        ManiRonM Offline
        ManiRonM Offline
        ManiRon
        wrote on last edited by ManiRon
        #3

        @mrjj I meant like a table but it should be a Tree widget

        Untitled.jpg

        Need grid in between row and columns

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

          This is not supported out-of-the box, you have to paint it by your own - either by reimplementing paintEvent() or maybe with a QStyledItemDelegate. But both are not trivial (for you)

          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
          • mrjjM mrjj

            Hi
            Do you mean like this
            alt text

            ManiRonM Offline
            ManiRonM Offline
            ManiRon
            wrote on last edited by
            #5
            This post is deleted!
            1 Reply Last reply
            0
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              Hi
              It was a treewidget with multiple columns :)

              maybe easier to see here
              alt text

              anyway, this is a Delegate as @Christian-Ehrlicher talks about.

              class GridDelegate : public QStyledItemDelegate
              {
              public:
                  explicit GridDelegate(QObject * parent = nullptr) : QStyledItemDelegate(parent) { }
              
                  void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
                  {
                     painter->setPen(QColor(Qt::black)); // set ink to black
                      painter->drawRect(option.rect);  // draw a rect covering cell area     
                      QStyledItemDelegate::paint(painter, option, index);  // tell it to draw as normally after
                  }
              };
              
              

              and you apply it via
              ui->treeWidget->setItemDelegate(new GridDelegate);

              However, this is a very simple example. it just
              draws a box on the cell area.
              You might want to to be slightly differnt for the the effect you want.

              1 Reply Last reply
              1
              • JonBJ JonB referenced this topic on

              • Login

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