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 can i add a button in the 1st column in QTreeWidget?
Qt 6.11 is out! See what's new in the release blog

how can i add a button in the 1st column in QTreeWidget?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 4.6k 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 last edited by opengpu2
    #1

    how can i add a button in the 1st column in QTreeWidget?
    what i want is like this pic below, and bulb before the text is checkable and be be toggled.
    i tried to use multi-colum, when i add button at the cloumns after 1st column, it's OK.
    however, when i added the button as the 1st column, there is a problem, when the child and grandchild is expanded the 1st colum which only have a button become very wide...and there is often much blank space before the text of the 2nd column(how can i make the 2nd column like the pic below which is not Aliagned? and go after the 1st button column?)
    http://help.autodesk.com/cloudhelp/2015/ENU/3DSMax/images/GUID-5DCC0C7F-6DF0-4B16-BC9E-9F614A62E2F5.png
    thank you!

    1 Reply Last reply
    0
    • RatzzR Offline
      RatzzR Offline
      Ratzz
      wrote on last edited by
      #2

      This might help you http://stackoverflow.com/questions/31316292/qt-clickable-widget-possibly-button-inside-qtreewidget

      --Alles ist gut.

      O 1 Reply Last reply
      1
      • RatzzR Ratzz

        This might help you http://stackoverflow.com/questions/31316292/qt-clickable-widget-possibly-button-inside-qtreewidget

        O Offline
        O Offline
        opengpu2
        wrote on last edited by
        #3

        @Ratzz thank you. but i think that's not enough.
        because
        i tried to use multi-colum, when i add button at the cloumns after 1st column, it's OK.
        however, when i added the button as the 1st column, there is a problem, when the child and grandchild is expanded the 1st colum which only have a button become very wide...and there is often much blank space before the text of the 2nd column(how can i make the 2nd column like the pic below which is not Aliagned? and go after the 1st button column?)

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          The solution is definitely using a Delegate. QTreeWidget uses a QTreeView and a QStandardItemModel under the hood. You should separate the Model from the View and apply a delegate to the first column of the view. See http://doc.qt.io/qt-5/model-view-programming.html for more details or chapter 10 of http://www.bogotobogo.com/cplusplus/files/c-gui-programming-with-qt-4-2ndedition.pdf

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          1
          • O Offline
            O Offline
            opengpu2
            wrote on last edited by
            #5

            thank you
            i did use delegate to edit a QTreeWidgetItem.
            howerver, i donnot know how to use delegate to add 2 buttons before the original QTreeWidgetItem and its icon...
            and i want to react the signals of the 2 buttons...

            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