Results 1 to 3 of 3

Thread: Filling empty cells in QTableWidget

  1. #1
    Join Date
    May 2009
    Posts
    17
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Filling empty cells in QTableWidget

    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!

    my last trying code (after many others...) was:
    Qt Code:
    1. QItemSelectionModel *selectionModel = ui->tableWidget->selectionModel();
    2. QModelIndexList itemsList = selectionModel->selectedIndexes();
    3.  
    4. foreach(item, listaItens)
    5. {
    6. item.model()->setData(item, ui->lineEdit->text());
    7. }
    To copy to clipboard, switch view to plain text mode 

    Thank you already!
    Last edited by lyucs; 20th October 2009 at 17:06.

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Filling empty cells in QTableWidget

    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.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    May 2009
    Posts
    17
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Filling empty cells in QTableWidget

    Oh, that might work!
    thanks

Similar Threads

  1. Replies: 2
    Last Post: 11th March 2009, 03:00
  2. Sorting QTableWidget alters selectioin of cells
    By zarkzervo in forum Qt Programming
    Replies: 2
    Last Post: 8th January 2009, 15:13
  3. Focus of cells in a QTableWidget
    By SailinShoes in forum Qt Programming
    Replies: 4
    Last Post: 9th June 2008, 09:19
  4. QTableWidget, header cells margin
    By DpoHro in forum Qt Programming
    Replies: 4
    Last Post: 18th January 2008, 00:38
  5. QTableWidget click in empty space results in error?
    By Giel Peters in forum Qt Programming
    Replies: 4
    Last Post: 21st January 2006, 01:07

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.