Unsolved Data method implementation in QStandardItemModel
-
Hi All,
Is there any hint to (re-)implement data method in QStandartItemModel used with QTreeView?
For some reasons, I need to control my QStandardItem array in the model such as highlighting/updating a specific row.
I have no luck so far with setIndexWidget and setData.
How can I return or set a QStandartItem in DisplayRole within the model?Any ideas?
Many thanks in advance for your help.
Regards,
Sat -
@ShinSat said in data method implementation in QStandardItemModel:
highlighting/updating a specific row
void highlightRow(QAbstractItemModel* const mdl, int row, const QModelIndex& parent=QModelIndex()){ Q_ASSERT(!parent.isValid() || parent.model()==mdl); Q_ASSERT(row>=0 && row<mdl->rowCount(parent)); const int colCount =mdl->columnCount(parent) for(int i=0;i<colCount ;++i) mdl->setData(mdl->index(row,i,parent),QBrush(Qt::red),Qt::BackgroundRole); } void unHighlightRow(QAbstractItemModel* const mdl, int row, const QModelIndex& parent=QModelIndex()){ Q_ASSERT(!parent.isValid() || parent.model()==mdl); Q_ASSERT(row>=0 && row<mdl->rowCount(parent)); const int colCount =mdl->columnCount(parent) for(int i=0;i<colCount ;++i) mdl->setData(mdl->index(row,i,parent),QVariant(),Qt::BackgroundRole); }
-
@VRonin Thanks for an update!
SO,,,, I can switch the two methods with QTimer or something, correct?
Also, one thing I'm not sure is if I can return QStandartItem from Displayrole of QStandartItemModel becaue it's not working in my environment, which is PyQt5.1 on Win7.
Is this a recommended or a proven way to handle custom QStandardItems between QStandardItemModel and QTreeView?Sat
-
@ShinSat said in data method implementation in QStandardItemModel:
if I can return QStandartItem from Displayrole of QStandartItemModel
You can but I don't see the point.
QStandartItemModel::data()
callsQStandartItem::data()
. Also, if you returnQStandartItem
for that role you'll also have to implement a custom delegate that can handle displayingQStandartItem
it's not working in my environment
In C++ you just need to use
QVariant::fromValue
but since it's a template I'm not sure how it translates to Python -