QTableWidget/QTableView accepting QStringList data
I am trying to use QTableWidget or QTableView subclassing either QTableWidgetItem or QAbstractTableModel class to return QStringList data type as QVarient in the Data() re-implementation. I would like to show two strings in each cell of the table, one for lable and one for actual values in QString format. This is for a realtime display of measured data. The Subclass compiled ok but when i run, the cells in the table of either the QTableView or QTable Widget show nothing. If i change the return type to a single QString data , they show up fine.
I am assuming that the sub-class of QTableWidgetItem/ QAbstractTableModel returning QStringList data correctly but the QTableWidget or QTableView internal routine to process data returned from the Data() can not handle this QStringList data correctly even though the QStringList is one of the valid QVariant data type. It seems like they expect a single value to be returned from the data() and when it is not it does not know what to do.
My question is: is there a way i can sub-class either the qtableView or QTableWidget to provide a way to accept the QStringList data type.
This can be extended to more that n strings in the QStringList.
Appreciate for help or advices.
I would subclass [[Doc:QStyledItemDelegate]] and reimplement the sizeHint (necessary for the calculation of the row heights and column widths) and paint methods.
Can you explain a little bit more? My problem is i don't know a way to pass multiple strings from QAbstractTableModel to QTableView. Once i get the data, i can use delegate to display them properly.
As the models are QVariant based, you can pass as QStringList as value for an index without problems.
You then pass the string list to the delegate - more correctly, the view calls the delegate with the index in question and the model it belongs to. The delegate is is responsible for splitting it up and displaying it in the way you want. The [[Doc:QAbstractItemDelegate]] API docs show you a small example for a paint method.