PDA

View Full Version : QTableWidget->items



calireno
8th October 2009, 09:43
Hi !

I've desperately been trying to get a QList of all the QTableWidgetItem items stored in a QTableWidget for the past few hours but : no luck.

my temporary solution is to select all the items in the table with selectAll() and then run selectedItems() which returns a QList of all the items in my table.



myTable->selectAll();
QList<QTableWidgetItem *> selectedCells = myTable->selectedItems();


I really want to avoid doing this for several reasons, the main one being that it's obviously not the right way to go, but I can't get this to work :


QList<QTableWidgetItem *> allCells = myTable->items( const QMimeData * data);


I don't really understand what "const QMimeData * data" is about and why i can't just get a full QList as easily as the selectedItems() method does.

Any help would be greatly appreciated, i'm loosing my mind on this right now.

Thanks !

Renaud

jano_alex_es
8th October 2009, 10:00
you can use rowCount () and columnCount(); two for and add the item to a list.



int iColumns = my_table.columnCount();
int iRows = my_table.rowCount();
QList<QWidgetItem*> myList;

for(int i = 0; i < iRows; ++i)
{
for(int j = 0; j < iColumn; ++j)
{
QTableWidgetItem* pWidget = my_table->item(i, j);
myList.append(pWigdet);
pWidget = 0;
}
}





I don't really understand what "const QMimeData * data" is about and why i can't just get a full QList as easily as the selectedItems() method does.

Well, you can call "items" without attributes.


QList<QTableWidgetItem *> allCells = myTable->items( );

QT Assistant says "If the object was not created by a QTreeWidget in the same process, the list is empty.", maybe that's why the function is not working in your code. Anyway, the first solution should work.

calireno
8th October 2009, 18:16
Thank you so much for your quick answer.

Solution number 1 works great however solution number 2 tells me i need to give an argument to items( )


1>.\mainwindow.cpp(279) : error C2660: 'QTableWidget::items' : function does not take 0 arguments

Solution 1 works for me but I just thought items( ) was a "cleaner" to do this.

Thanks again Alex !