PDA

View Full Version : Filling empty cells in QTableWidget



lyucs
20th October 2009, 15:54
I have a simple application, in which I want to fill multiple cells with the same QString at the same time.
My first and innocent try was using 'selectedItems' from QTableWidget, and iterating in the list, using 'setText' for all QWidgetItems of the list.

Turns out that 'selectedItems' does not return empty cells, making it utterly useless to me.
Reading the doc, I was recommended a 'selectedIndexes'.
The problem is: it returns a QModelIndexList. It is a list, all right, but I've got no Idea on how to use the QModelIndex items.

I tried a lot, seriously, and read tons of API (for example: http://doc.trolltech.com/4.0/model-view-selection.html)

Well, my last resort is, as always was, here.
And you guys always help! :D

my last trying code (after many others...) was:


QItemSelectionModel *selectionModel = ui->tableWidget->selectionModel();
QModelIndexList itemsList = selectionModel->selectedIndexes();
QModelIndex item;

foreach(item, listaItens)
{
item.model()->setData(item, ui->lineEdit->text());
}


Thank you already!

spirit
20th October 2009, 16:18
if you need to fill all empty items you can use QTableWidget::findItems and then fill items in a loop.
or you can use more common method QAbstractItemModel::match.

lyucs
20th October 2009, 17:12
Oh, that might work!
thanks