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. Span cells in QTableView from model
Qt 6.11 is out! See what's new in the release blog

Span cells in QTableView from model

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 2.7k Views 2 Watching
  • 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
    Mark81
    wrote on last edited by Mark81
    #1

    I want to achieve something like this (image from the web):

    alt text

    where each "section" spans over all the columns. This should be accomplished by using the void QTableView::setSpan(int row, int column, int rowSpanCount, int columnSpanCount) method. But the UI has no way to know which rows are section. The model knows, i.e. I have an hidden column that allows me to distinguish if the current row is either a section row or data one.

    So, what is the best way to bring up this information to the UI in order to set the span?

    My (ugly*) thought: whenever the model changes, first clear all the spans, then cycle the rows one by one, get the model data, check the hidden field and set the span according.

    *ugly, but it actually works!

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      HI
      It's not possible to use UserRole for this? (custom role)
      So so it's like EditROle and Decoration role and a view can choose to honor it.

      M 1 Reply Last reply
      0
      • mrjjM mrjj

        HI
        It's not possible to use UserRole for this? (custom role)
        So so it's like EditROle and Decoration role and a view can choose to honor it.

        M Offline
        M Offline
        Mark81
        wrote on last edited by Mark81
        #3

        @mrjj said in Span cells in QTableView from model:

        HI
        It's not possible to use UserRole for this? (custom role)
        So so it's like EditROle and Decoration role and a view can choose to honor it.

        As far as I know with DecorationRole and the other display ones (i.e. BackgroundRole) you can easily change the appearance in terms of colors and icons. I don't know if you can also suppress the cell borders as well.

        mrjjM 1 Reply Last reply
        0
        • M Mark81

          @mrjj said in Span cells in QTableView from model:

          HI
          It's not possible to use UserRole for this? (custom role)
          So so it's like EditROle and Decoration role and a view can choose to honor it.

          As far as I know with DecorationRole and the other display ones (i.e. BackgroundRole) you can easily change the appearance in terms of colors and icons. I don't know if you can also suppress the cell borders as well.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi
          I mean to flag a row if should be a section type.
          Would be less convoluted than having a hidden col. (IMHO)

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

            The KDE API has a very similar functionality using KCategorizedSortFilterProxyModel/KCategorizedView/KCategoryDrawer: https://api.kde.org/frameworks/kitemviews/html/annotated.html but it implements only a list view, not a table.
            The alternative is to use a tree model/view, set the categories as top items and the rest as leaves of the tree

            "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