Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. QAbstractListModel setHeaderData
Forum Updated to NodeBB v4.3 + New Features

QAbstractListModel setHeaderData

Scheduled Pinned Locked Moved Unsolved Qt for Python
pyside2
3 Posts 2 Posters 914 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.
  • A Offline
    A Offline
    Abdulrahman
    wrote on last edited by
    #1

    Hello All,
    I implemented setHeaderData using PySide2, but it returns false. So what is wrong with this implementation. In Documentation setHeaderData(section, orientation, value[, role=Qt.EditRole]), so what is the value (i putted it with zero as i searched and didn't find answer)
    833c2b22-e33b-42fb-a7aa-1f1179c0a4a3-image.png

    JonBJ 1 Reply Last reply
    0
    • A Abdulrahman

      Hello All,
      I implemented setHeaderData using PySide2, but it returns false. So what is wrong with this implementation. In Documentation setHeaderData(section, orientation, value[, role=Qt.EditRole]), so what is the value (i putted it with zero as i searched and didn't find answer)
      833c2b22-e33b-42fb-a7aa-1f1179c0a4a3-image.png

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Abdulrahman
      What is your question? QAbstractListModel::setHeaderData() (inherited from QAbstractItemModel) always returns false, see https://code.woboq.org/qt5/qtbase/src/corelib/itemmodels/qabstractitemmodel.cpp.html#_ZN18QAbstractItemModel13setHeaderDataEiN2Qt11OrientationERK8QVarianti.

      If you want it to do something you have to override it in your subclass. Which your code does not show.

      I implemented setHeaderData using PySide2, but it returns false.

      Well if you do your code does not show so.....

      (Given that you have a headerData() returning something, you would also need a setHeaderData() which goes return True. Though so long as your headerData() returns something as it does without any reference to what is in the data, as it stands you probably don't want a setHeaderData() (because it wouldn't do anything), instead your current code simply should not call it.)

      BTW, setHeaderData(..., role = 0) is not a good idea. That is DisplayRole, not the default EditRole. Either don't specify it and leave at default EditRole, or use the constants in Python from QtCore.Qt.EditRole etc.

      A 1 Reply Last reply
      1
      • JonBJ JonB

        @Abdulrahman
        What is your question? QAbstractListModel::setHeaderData() (inherited from QAbstractItemModel) always returns false, see https://code.woboq.org/qt5/qtbase/src/corelib/itemmodels/qabstractitemmodel.cpp.html#_ZN18QAbstractItemModel13setHeaderDataEiN2Qt11OrientationERK8QVarianti.

        If you want it to do something you have to override it in your subclass. Which your code does not show.

        I implemented setHeaderData using PySide2, but it returns false.

        Well if you do your code does not show so.....

        (Given that you have a headerData() returning something, you would also need a setHeaderData() which goes return True. Though so long as your headerData() returns something as it does without any reference to what is in the data, as it stands you probably don't want a setHeaderData() (because it wouldn't do anything), instead your current code simply should not call it.)

        BTW, setHeaderData(..., role = 0) is not a good idea. That is DisplayRole, not the default EditRole. Either don't specify it and leave at default EditRole, or use the constants in Python from QtCore.Qt.EditRole etc.

        A Offline
        A Offline
        Abdulrahman
        wrote on last edited by
        #3

        @JonB Thanks for your reply,
        My question is if i don't need to implement setHeaderData() and my code shouldn't call it, How to make ListView{} call it and set displayed data with header's text (i attached picture for code of main.qml).

        edd9ba30-5acf-4cd2-8f46-c20e869c5548-image.png

        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