PDA

View Full Version : Display QStandardItem Properties in a QTableView row



Phlucious
17th December 2012, 23:45
I have a custom object based on QStandardItem that possesses several properties. Normally these objects are listed in a QTreeView, but occasionally I'd like to display a report with them in a QTableView.

Let's say, for example, that Person derives from QStandardItem and has the properties Name, Address, FavoriteColor, and SpouseName. The Person's DisplayRole is usually Name, but for the QTableView I'd like to have an entire row populated by their Name, Address, FavoriteColor, and SpouseName, each in a column.

Is there a straightforward Qt way to display a single QStandardItem across several rows like this? All I can think of is spawning a row of generic QStandardItems, each with its text set to the property I want, but that seems... rough, at best.

Or... is my concept fundamentally flawed at the outset when I had Person inherit from QStandardItem?

Talei
17th December 2012, 23:55
Maybe try another way around, create a delegate for the QTableView and display appropriate text for particular cell.
That way if in the feature You decide to use QListView then simply create another delegate and use already existing data structure without changing a thing with it.

Phlucious
18th December 2012, 01:01
Yes, delegates communicate the idea that I'm trying to accomplish. My thought is that I would assign a QStandardItem derivative to every row, and then assign a delegate to each column to display a certain ItemDataRole (http://doc.qt.digia.com/qt/qt.html#ItemDataRole-enum) of that QStandardItem.

Doesn't QTableView work on the premise that QStandardItems are assigned to cells, not rows, though? That's my point of confusion.

Talei
18th December 2012, 01:19
Yes they are per cell not the row.