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.
  • M Offline
    M Offline
    ManiRon
    wrote on 26 Dec 2019, 10:30 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
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 26 Dec 2019, 10:50 last edited by
      #2

      Hi
      Do you mean like this
      alt text

      M 2 Replies Last reply 26 Dec 2019, 11:37
      0
      • M mrjj
        26 Dec 2019, 10:50

        Hi
        Do you mean like this
        alt text

        M Offline
        M Offline
        ManiRon
        wrote on 26 Dec 2019, 11:37 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
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 26 Dec 2019, 12:16 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
          • M mrjj
            26 Dec 2019, 10:50

            Hi
            Do you mean like this
            alt text

            M Offline
            M Offline
            ManiRon
            wrote on 27 Dec 2019, 04:45 last edited by
            #5
            This post is deleted!
            1 Reply Last reply
            0
            • M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 27 Dec 2019, 10:52 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
              • J JonB referenced this topic on 4 Aug 2023, 19:03

              1/6

              26 Dec 2019, 10:30

              • Login

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