Results 1 to 7 of 7

Thread: QTableWidget select only visible cells

  1. #1
    Join Date
    Apr 2011
    Posts
    195
    Thanks
    49
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default QTableWidget select only visible cells

    Hi
    A little question:

    I have a QTableWidget with lots of rows. I developed a filter, which shows and hides rows.
    But if a filter is active, i.e 3 of 300 rows are shown:

    001 row
    299 row
    300 row

    If the user selects 001 and 299 all the rows between 1 and 299 are also selected.
    How can I solve the problem?

    thank u

  2. #2
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableWidget select only visible cells

    Depends on what your filter does and how it does it.

    To me it sounds that you're doing something odd that's why you're getting hidden items back (or not doing something).

    If you're using QTableWidget then
    QModelIndexList QAbstractItemView::selectedIndexes () const [virtual protected]
    This convenience function returns a list of all selected and non-hidden item indexes in the view. The list contains no duplicates, and is not sorted.
    Should be all you need.

  3. #3
    Join Date
    Apr 2011
    Posts
    195
    Thanks
    49
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableWidget select only visible cells

    ok thank you very much..., but I don't want the indexes. I want the rows.
    I can't find a method to get the visible rows. So I have to do a workaround with the QModelIndexes?


    Added after 6 minutes:


    here is my workaround:

    I added a method to my QTableWidget:
    Qt Code:
    1. QList<int> MyTable::getVisibleSelectedRows()
    2. {
    3. QModelIndexList indexes = selectedIndexes();
    4. QList<int> rows;
    5. for(int i = 0; i < indexes.size(); i++){
    6. int row = indexes.value(i).row();
    7. if(!rows.contains(row))
    8. rows.append(row);
    9. }
    10. return rows;
    11. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Qiieha; 22nd December 2011 at 14:37.

  4. #4
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableWidget select only visible cells

    That's redundant.

    You're converting list of model indexes without duplicates (selectedIndexes() doesn't contain duplicates) into list of row indexes without duplicates.

    And it's what you've said you don't want...

    Anyway, I don't think you can get a 'row'.
    Having a row index and column index you can get an item, but that's all.

    you may use
    Qt Code:
    1. QList<QTableWidgetItem *> QTableWidget::selectedItems ()
    To copy to clipboard, switch view to plain text mode 
    If you want list of selected items, but documentation doesn't say if it takes visibility into account, you'd need to check.

  5. #5
    Join Date
    Apr 2011
    Posts
    195
    Thanks
    49
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableWidget select only visible cells

    You are right, there aren't duplicates of QModelIndexes, but there are duplicates of rows.
    (One row has i.e. 3 columns, so i get three QModelIndexes and every QModelIndex returns the same row.)
    So my method shouldn't be redundant...

  6. #6
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableWidget select only visible cells

    That's correct, I haven't checked deep enough, my bad.

  7. The following user says thank you to Spitfire for this useful post:

    Qiieha (23rd December 2011)

  8. #7
    Join Date
    Apr 2011
    Posts
    195
    Thanks
    49
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableWidget select only visible cells

    thank for your help

Similar Threads

  1. Replies: 7
    Last Post: 24th May 2011, 04:36
  2. Replies: 1
    Last Post: 6th January 2011, 04:19
  3. read QTableWidget cells
    By navid in forum Newbie
    Replies: 8
    Last Post: 4th April 2010, 10:40
  4. Focus of cells in a QTableWidget
    By SailinShoes in forum Qt Programming
    Replies: 4
    Last Post: 9th June 2008, 08:19
  5. Text in QTableView cells not visible
    By juliarg in forum Newbie
    Replies: 2
    Last Post: 22nd March 2007, 15:49

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.