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. QTreeWidget gird lines
Forum Update on Monday, May 27th 2025

QTreeWidget gird lines

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 454 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.
  • G Offline
    G Offline
    GaryT
    wrote on last edited by
    #1

    I am new to QT and I am trying to figure out how to add gridlines to the sections of a QTreeWidget. From what I can see, it looks like you have to override the paintEvent() or maybe the QStyledItemDelegate. I have also seen references to using style sheets. I was wondering if there is a recommended way.

    Thanks in advance
    Gary

    JonBJ 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      I am unsure of the result you seek. Do you have an image of what you would like to obtain ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • G GaryT

        I am new to QT and I am trying to figure out how to add gridlines to the sections of a QTreeWidget. From what I can see, it looks like you have to override the paintEvent() or maybe the QStyledItemDelegate. I have also seen references to using style sheets. I was wondering if there is a recommended way.

        Thanks in advance
        Gary

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by
        #3

        @GaryT
        If you are happy with the CSS solution at https://stackoverflow.com/questions/33911102/qtreeview-grid-line-color

        QTreeView::item { border: 0.5px ; border-style: solid ; border-color: lightgray ;}
        

        that is the simplest. (A QTreeWidget is a QTreeView. Above should work for you, else try QTableWidget instead.) Read the comments there for a limitation.

        Otherwise @mrjj's code at https://forum.qt.io/topic/110101/how-to-create-grid-line-in-qtreewidget/6 shows a minimal delegate.

        G 1 Reply Last reply
        1
        • JonBJ JonB

          @GaryT
          If you are happy with the CSS solution at https://stackoverflow.com/questions/33911102/qtreeview-grid-line-color

          QTreeView::item { border: 0.5px ; border-style: solid ; border-color: lightgray ;}
          

          that is the simplest. (A QTreeWidget is a QTreeView. Above should work for you, else try QTableWidget instead.) Read the comments there for a limitation.

          Otherwise @mrjj's code at https://forum.qt.io/topic/110101/how-to-create-grid-line-in-qtreewidget/6 shows a minimal delegate.

          G Offline
          G Offline
          GaryT
          wrote on last edited by
          #4

          Thanks for all your help.

          Gary

          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