Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QAbstractListModel setHeaderData



  • 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



  • @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.



  • @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


Log in to reply