Important: Please read the 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)

  • @Abdulrahman
    What is your question? QAbstractListModel::setHeaderData() (inherited from QAbstractItemModel) always returns false, see

    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).


Log in to reply