QStandardItem, store property
-
I am using QStandardItem to show a text cell in a QTableView, the text in the cell is so long, its a full path, so I've cut down to just the file name. I want to store the original as a hidden property with the item, can this be done?
I can't see any property or setProperty methods on this class.
[Edit] Sorted, the original data is now stored in the tooltip.
-
I am using QStandardItem to show a text cell in a QTableView, the text in the cell is so long, its a full path, so I've cut down to just the file name. I want to store the original as a hidden property with the item, can this be done?
I can't see any property or setProperty methods on this class.
[Edit] Sorted, the original data is now stored in the tooltip.
@SPlatten
QStandardItem
does not have an arbitrary "property". But it does havesetData()
/data()
with an arbitraryrole
to store/retrieve whatever you want in the model.EDIT Your
[Edit] Sorted, the original data is now stored in the tooltip.
A bit naughty, to use the tooltip for something which you actually mean to retrieve.
EDIT2
From your latest I see you have come to same conclusion! -
@SPlatten
QStandardItem
does not have an arbitrary "property". But it does havesetData()
/data()
with an arbitraryrole
to store/retrieve whatever you want in the model.EDIT Your
[Edit] Sorted, the original data is now stored in the tooltip.
A bit naughty, to use the tooltip for something which you actually mean to retrieve.
EDIT2
From your latest I see you have come to same conclusion! -
@SPlatten
QStandardItem
does not have an arbitrary "property". But it does havesetData()
/data()
with an arbitraryrole
to store/retrieve whatever you want in the model.EDIT Your
[Edit] Sorted, the original data is now stored in the tooltip.
A bit naughty, to use the tooltip for something which you actually mean to retrieve.
EDIT2
From your latest I see you have come to same conclusion!@JonB , When I create the item:
QString strOriginal, strValue(it.value().toString()); if ( f == DataSets::mcuint16Filename ) { int intLDelmtr = strValue.lastIndexOf("/"); if ( intLDelmtr >= 0 ) { strOriginal = strValue; strValue = strValue.mid(intLDelmtr + 1); } } QStandardItem* psItem(new QStandardItem(strValue)); psItem->setFlags(psItem->flags() & ~Qt::ItemIsEditable); if ( strOriginal.isEmpty() != true ) { psItem->setData(strOriginal); } lstRow.append(psItem);
In the lambda slot that handles the double click:
QModelIndex objIndex(objColumn.at(c)); QString strItem(objIndex.data().toString());
c is an integer between 0 and number of columns, the above always gives the text assigned to the column which in the case of the file name (column 0) is just the file name without the path.
How do I get access to the QStandardItem that was appended to the row?
[Edit] Done:
QStandardItem* pItem(this->mpsiModel->itemFromIndex(objIndex));