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. QTreeView with multiple Widgets in columns?

QTreeView with multiple Widgets in columns?

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 12.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.
  • M Offline
    M Offline
    ManasQt
    wrote on last edited by
    #1

    Hi,
    How to insert a check box , button and combobx in each column inside QTreeView?

    please help me :(

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dangelog
      wrote on last edited by
      #2

      setIndexWidget comes to mind, or a custom delegate. Note that if you just want to display a checkbox next to an item, you can just set the Qt::ItemIsUserCheckable flag (and manage the value for the Qt::CheckStateRole in data/setData).

      Software Engineer
      KDAB (UK) Ltd., a KDAB Group company

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        You can not do it. setIndexWidget will only allow setting a single item in a cell, not multiple. However, you can of course make your own compound widget that consists of a checkbox, a button and a combobox in a layout, and set an instance of that widget in a tree view.

        Note however, that using setIndexWidget is not very performant for large models.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          ManasQt
          wrote on last edited by
          #4

          Hi Andre.

          bq. make your own compound widget that consists of a checkbox, a button and a combobox in a layout, and set an instance of that widget in a tree view

          I can do that but , how to show different widget in different columns? like

          QTreeView will have ,

          col-1 | col2 | col3 ----

          QLineEdit QCheckBox QComboBox -----


          is it possible to achieve this using QStyledItemDelegate? or any other way?
          please put me in right direction with some sample code.

          thanks in advance.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            I thought you wanted to put multiple widgets in a single cell. If you just want one item per cell, just put your widgets in your cells directly as directed earlier by peppe, and take note of his suggestion that you don't need to use a QCheckBox widget because that can be rendered by the item view (ok, the default delegate, but that is besides the point) directly.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              giesbert
              wrote on last edited by
              #6

              Or, if it is enough to have the widgets for editing, I would prefer a QStyledItemDelegate subclass as item delegate in the view. That way, you only have one widget active at one point in time and only create them when the user starts editing the cells.

              Nokia Certified Qt Specialist.
              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

              1 Reply Last reply
              0
              • M Offline
                M Offline
                ManasQt
                wrote on last edited by
                #7

                Hi Gerolf,
                can you please show me with some sample code on how to get it.
                thanks

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  giesbert
                  wrote on last edited by
                  #8

                  You can find good examples "in the docs":http://doc.qt.nokia.com/4.7/model-view-programming.html#delegate-classes

                  Nokia Certified Qt Specialist.
                  Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                  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