PDA

View Full Version : QTableWidget::selectedItems()



maxpower
26th January 2009, 20:46
I am using QTableWidget to create a table of mp3s and their ID3 tag information. I want to be able to handle multiple selections in the the table. It seems selectedItems() behaves differently based on how the items were selected. I have my table set to only select rows. When two contiguous rows are selected, item.at(0) is row 0 col 0 and item.at(1) is row 1 col 0. If the selected rows are not contiguous item.at(0) is row 0 col 0 and item.at(1) is row 0 col 1. I can I code it so that my functions work either way? Is there a better way to get the selected items? Or will using a mode/view combo solve my problem?

Thanks
mAx

caduel
26th January 2009, 21:13
Better use QItemSelectionModel::selectedRows() (and then map those QModelIndexes to a QTableWidgetItem*).

Apart from that: why not use the chance and roll your own model and use QTableView? (Believe me, it's worth the effort.)

maxpower
27th January 2009, 18:57
Thanks. I used the QStandardItemModel with a QItemSelectionModel and it is working they way I expected. I am not sure of the benefit of creating a custom model. I looked at some other custom models and they made sense as to why you would create them (an items value was based on the value of other items and this was computed internally by the model). I just don't see how my model of mp3 tag info would benefit.

Thanks
mAx

Olivia
29th April 2011, 15:34
What QTableWidget::selectedItems return if there isn't anything selected?


EDIT:

It hit me a couple moments after posting.... An empty list ;).