Results 1 to 3 of 3

Thread: QTableWidget->items

  1. #1
    Join Date
    Oct 2008
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy QTableWidget->items

    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.

    Qt Code:
    1. myTable->selectAll();
    2. QList<QTableWidgetItem *> selectedCells = myTable->selectedItems();
    To copy to clipboard, switch view to plain text mode 


    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 :

    Qt Code:
    1. QList<QTableWidgetItem *> allCells = myTable->items( const QMimeData * data);
    To copy to clipboard, switch view to plain text mode 


    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

  2. #2
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: QTableWidget->items

    you can use rowCount () and columnCount(); two for and add the item to a list.

    Qt Code:
    1. int iColumns = my_table.columnCount();
    2. int iRows = my_table.rowCount();
    3. QList<QWidgetItem*> myList;
    4.  
    5. for(int i = 0; i < iRows; ++i)
    6. {
    7. for(int j = 0; j < iColumn; ++j)
    8. {
    9. QTableWidgetItem* pWidget = my_table->item(i, j);
    10. myList.append(pWigdet);
    11. pWidget = 0;
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 


    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.

    Qt Code:
    1. QList<QTableWidgetItem *> allCells = myTable->items( );
    To copy to clipboard, switch view to plain text mode 

    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.
    Last edited by jano_alex_es; 8th October 2009 at 11:47.

  3. #3
    Join Date
    Oct 2008
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableWidget->items

    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( )

    Qt Code:
    1. 1>.\mainwindow.cpp(279) : error C2660: 'QTableWidget::items' : function does not take 0 arguments
    To copy to clipboard, switch view to plain text mode 

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

    Thanks again Alex !

Similar Threads

  1. QComboBox in QTableWidget : display troubles.
    By Nyphel in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2007, 23:29
  2. Select columns from a QTableWidget
    By toglez in forum Qt Programming
    Replies: 10
    Last Post: 7th October 2007, 15:15
  3. QTableWidget (resizing rows, turning off selection, etc.)
    By kiss-o-matic in forum Qt Programming
    Replies: 6
    Last Post: 11th January 2007, 01:57
  4. QTableWidget editing question
    By Trasmeister in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2006, 18:46
  5. Replies: 6
    Last Post: 5th March 2006, 21:05

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.