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. [Worked around] How to set header text of QAbstractItemModel in a QTreeView

[Worked around] How to set header text of QAbstractItemModel in a QTreeView

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 5.0k 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
    Moschops
    wrote on last edited by
    #1

    I have a QTreeView, and its model is (a subclass of) a QAbstractItemModel.

    The model has two columns, and they are labelled "1" and "2". I suspect this is the default labels.

    I want them to be blank, so I put this into the constructor of the model to test my ability to set the header text:

    @bool worked = setHeaderData(1, Qt::Horizontal, QVariant(QString("Beans")));@

    Worked has the value "false". It does not work. The label does not get changed. I tried this as well:

        @setHeaderData(1, Qt::Horizontal, QVariant(QString("Beans")), Qt::DisplayRole);@
    

    and this also does not work.

    How can I change the header text of a QAbstractItemModel?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Moschops
      wrote on last edited by
      #2

      I have read them. I would say they are an acceptable introduction; I have read technical documents that really are "very good", and these are not. They're acceptable, but not "very good". :) I can't recall a "very good" set of online documentation right now, but Maple's online documentation is an example of some truly horrific documentation. :)

      Thanks very much. In the end, I overrode the QAbstractItemModel::headerData() function and simply intercepted any calls that wanted DisplayRole data. A bit of a silly solution, but it works.

      1 Reply Last reply
      0
      • JeroentjehomeJ Offline
        JeroentjehomeJ Offline
        Jeroentjehome
        wrote on last edited by
        #3

        Huh?? What do you mean with:
        bq. intercepted any calls that wanted DisplayRole data
        The hole point of Model/View usage is that the model holds the data, not the view or anyone else........

        Greetz, Jeroen

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

          I mean that my subclass of QAbstractItemModel now has a function headerData(), so when the headerdata is required and that function is called, it goes through my code and I simply return the value I want.

          I have no idea what value is held in the model for the header text; because I don't know how to change the value for the header text in the model, I don't fetch it from the model. Calling the model's setHeaderData function to try to set the header data did not work.

          1 Reply Last reply
          0
          • JeroentjehomeJ Offline
            JeroentjehomeJ Offline
            Jeroentjehome
            wrote on last edited by
            #5

            No, you have to implement/overwrite the setHeaderData your self and store the information in your model.

            Greetz, Jeroen

            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