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. [Solved] Different headers in QTableViews using same model

[Solved] Different headers in QTableViews using same model

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.3k Views 1 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.
  • A Offline
    A Offline
    aka0
    wrote on last edited by
    #1

    Hi,
    I have two QTableViews which use the same model (a subclass of QAbstractItemModel). These tables display data in two different ways and I would like them to display two different strings in their horizontal headers. I already override the QAbstractItemModel::headerData method and return a string for the Qt::DisplayRole, but I can´t distinguish which table is requesting it, so until now I always return the same string, which is not optimal.
    I guess a solution might be creating two new roles (something like MyRoles::DisplayRoleForTable1 and MyRoles::DisplayRoleForTable2) and make each table use one of those instead of Qt::DisplayRole, but I am not sure how to achieve this.

    I would be grateful for any help.

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

      Hi and welcome to devnet,

      You could use a "QIdentityProxyModel":http://qt-project.org/doc/qt-4.8/qidentityproxymodel.html between your views (one per view) and your model to return the string you want.

      Hope it helps

      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
      • A Offline
        A Offline
        aka0
        wrote on last edited by
        #3

        Nice and clean solution, thanks a lot!

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You're welcome !

          Don't forget to update the thread's title prepending solved so other forum users may know that a solution has been found :)

          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

          • Login

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