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 - where to call setIndexWidget() for custom widgets in view
Forum Updated to NodeBB v4.3 + New Features

QTreeView - where to call setIndexWidget() for custom widgets in view

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 2.2k 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.
  • gde23G Offline
    gde23G Offline
    gde23
    wrote on last edited by
    #1

    Hello,

    I want to style my QtreeView to show some more information in each cell.
    The result should look kind of this:
    alt text
    I've managed to set the widget by explicitly calling setIndexWidget() on some index.
    ItemDelegates do not work for me since I really need the headerData displayed in each cell (it is different from row to row)

    I want the widgets to be deployed by the view itself when an item is added and removed when an item is removed, or the column count of the item changes however I do not exactly get where to implement this. And how do I connect the widgets to the ItemModel? Is there some example for this??

    What I've done so far is adding the setIndexWidget() call to rowsInserted() however this only works for newly added rows and not when the whole model is reset.

    And is it somehow possible to only add widgets to items that are visible which might be good for performance reasons??

    VRoninV 1 Reply Last reply
    0
    • gde23G gde23

      Hello,

      I want to style my QtreeView to show some more information in each cell.
      The result should look kind of this:
      alt text
      I've managed to set the widget by explicitly calling setIndexWidget() on some index.
      ItemDelegates do not work for me since I really need the headerData displayed in each cell (it is different from row to row)

      I want the widgets to be deployed by the view itself when an item is added and removed when an item is removed, or the column count of the item changes however I do not exactly get where to implement this. And how do I connect the widgets to the ItemModel? Is there some example for this??

      What I've done so far is adding the setIndexWidget() call to rowsInserted() however this only works for newly added rows and not when the whole model is reset.

      And is it somehow possible to only add widgets to items that are visible which might be good for performance reasons??

      VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      where to call setIndexWidget() for custom widgets in view?

      Nowhere.

      I want the widgets to be deployed by the view itself when an item is added and removed when an item is removed

      You are describing what a delegate does.

      ItemDelegates do not work for me since I really need the headerData displayed in each cell (it is different from row to row)

      ItemDelegates can do anything to a single cell. setItemWidget should only be used when the planets align on a full moon while under the northern lights (aka never).

      In the absolute worse case you can use a delegate like this one: https://pastebin.com/XrppLZ3m

      "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
      2
      • gde23G Offline
        gde23G Offline
        gde23
        wrote on last edited by
        #3

        @VRonin: Thanks for the quick reply.
        At the moment I am using Delegates, however they only show when a cell is edited.
        How can I achieve that the cells always look like the Delegate Widget looks like and not only while editing?

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

          http://doc.qt.io/qt-5/qstyleditemdelegate.html#paint

          "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
          2

          • Login

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