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 custom Header of QTreeWidget, use setHeaderItem & setItemWidget ?
Forum Update on Monday, May 27th 2025

how to custom Header of QTreeWidget, use setHeaderItem & setItemWidget ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 3 Posters 3.9k 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.
  • O Offline
    O Offline
    opengpu2
    wrote on 8 Aug 2016, 08:56 last edited by opengpu2 8 Aug 2016, 09:06
    #1

    how to custom Header of QTreeWidget, use setHeaderItem & setItemWidget ?
    i use setHeaderItem & setItemWidget, but it didnot work...
    do i have to inherite a child class of QHeaderView, to customize the Header?and if i have to use this method, is it possible to work fine when multi-column, and each column use setItemWidget to set a custom QWidget?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 8 Aug 2016, 08:58 last edited by
      #2

      Hi,

      Technically, there's no header for a QTreeWidgetItem. A QTreeWidgetItem is the content of a cell in a QTreeWidget.

      What exactly are you trying to achieve ?

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

      O 1 Reply Last reply 8 Aug 2016, 09:06
      0
      • S SGaist
        8 Aug 2016, 08:58

        Hi,

        Technically, there's no header for a QTreeWidgetItem. A QTreeWidgetItem is the content of a cell in a QTreeWidget.

        What exactly are you trying to achieve ?

        O Offline
        O Offline
        opengpu2
        wrote on 8 Aug 2016, 09:06 last edited by
        #3

        @SGaist sorry, type error, corrected

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Radek
          wrote on 8 Aug 2016, 09:52 last edited by
          #4

          Hi,

          I'd think the proper way would be to customize a QHeaderView.
          Then QTreeView::setHeader(QHeaderView * header) to set it to your tree view.

          There is no problem, there are only solutions. :)

          O 1 Reply Last reply 9 Aug 2016, 01:09
          1
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 8 Aug 2016, 10:54 last edited by
            #5

            What do you want to have in your header views ?

            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
            • O Offline
              O Offline
              opengpu2
              wrote on 9 Aug 2016, 01:08 last edited by
              #6

              custom QWidget, use setItemWidget to set it on QTreeWidgetItem, and then use setHeaderItem to set this QTreeWidgetItem on the header, but it didnot work...

              1 Reply Last reply
              0
              • R Radek
                8 Aug 2016, 09:52

                Hi,

                I'd think the proper way would be to customize a QHeaderView.
                Then QTreeView::setHeader(QHeaderView * header) to set it to your tree view.

                O Offline
                O Offline
                opengpu2
                wrote on 9 Aug 2016, 01:09 last edited by
                #7

                @Radek thank you, and if i customize a QHeaderView, is it able to set different QWidget on each column of the header?

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 9 Aug 2016, 06:50 last edited by
                  #8

                  That doesn't really answer the question. Can you give an example of widget you would like to have on your header view ?

                  In any case, you have this article here that explain how to do it for example with a QComboBox.

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

                  R 1 Reply Last reply 9 Aug 2016, 10:09
                  1
                  • S SGaist
                    9 Aug 2016, 06:50

                    That doesn't really answer the question. Can you give an example of widget you would like to have on your header view ?

                    In any case, you have this article here that explain how to do it for example with a QComboBox.

                    R Offline
                    R Offline
                    Radek
                    wrote on 9 Aug 2016, 10:09 last edited by
                    #9

                    @SGaist hi, my point wasn't to give a cooked solution but rather point to a direction where to look for one. Sry if it wasn't good enough, I'll try not to post like that anymore...

                    There is no problem, there are only solutions. :)

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 9 Aug 2016, 20:57 last edited by
                      #10

                      @Radek my answer wasn't directed to you, no worries ;)

                      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
                      1

                      7/10

                      9 Aug 2016, 01:09

                      • Login

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