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 fromQAbstractItemModel
) always returnsfalse
, 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 asetHeaderData()
which goesreturn True
. Though so long as yourheaderData()
returns something as it does without any reference to what is in the data, as it stands you probably don't want asetHeaderData()
(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 isDisplayRole
, not the defaultEditRole
. Either don't specify it and leave at defaultEditRole
, or use the constants in Python fromQtCore.Qt.EditRole
etc. -
@JonB Thanks for your reply,
My question is if i don't need to implementsetHeaderData()
and my code shouldn't call it, How to makeListView{}
call it and set displayed data with header's text (i attached picture for code of main.qml).