Results 1 to 12 of 12

Thread: TableView ProxyModel problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: TableView ProxyModel problem

    The code you posted did not work properly If you hide the rows in different orders you get varied results from nothing being highlighted to one item not being highlighted until you click on the table. I think this is close. I have to go to work. I will look closer at your code to see if I can figure out why it isn't working quite right...at least when it is highlighting, it is highlighting the correct number!

  2. #2
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: TableView ProxyModel problem

    On my Linux box the only problem that I experienced was sometimes the highlight didn't show up until the mouse was over the view. Works well otherwise.

    See if this fixes things. Add this statement to the MainWindow constructor:
    Qt Code:
    1. ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
    To copy to clipboard, switch view to plain text mode 
    and add an update at the end of the slot:
    Qt Code:
    1. void MainWindow::pbClicked(){
    2. QModelIndexList list = ui->tableView->selectionModel()->selectedRows();
    3. foreach(QModelIndex index, list){
    4. ui->tableView->hideRow(index.row());
    5. }
    6. highlightCells();
    7. ui->tableView->update();
    8. }
    To copy to clipboard, switch view to plain text mode 

    Edit: Oops. I see what you mean. It doesn't work if the view is sorted by a different column
    Last edited by norobro; 17th August 2011 at 04:43. Reason: updated contents

  3. #3
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: TableView ProxyModel problem

    I think adding the following statement to the MainWindow ctor and making highlightCells() a slot makes it work properly. The row numbers change on a sort (duh) and need to be rehighlighted.
    Qt Code:
    1. connect(ui->tableView->horizontalHeader(),SIGNAL(sectionClicked(int)),this,SLOT(highlightCells()));
    To copy to clipboard, switch view to plain text mode 
    Attached Files Attached Files

  4. #4
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: TableView ProxyModel problem

    Thanks....I will try it when I get back home this afternoon!

  5. #5
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: TableView ProxyModel problem

    It is still not always highlighting the cells after rows are hidden. I tried a couple different things for ui->tableview but I am not sure why sometimes it doesn't work. I will look at it some more tonight.

  6. #6
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: TableView ProxyModel problem

    Maybe this will solve it:
    Qt Code:
    1. void MainWindow::pbClicked(){
    2. QModelIndexList list = ui->tableView->selectionModel()->selectedRows();
    3. foreach(QModelIndex index, list){
    4. ui->tableView->hideRow(index.row());
    5. }
    6. highlightCells();
    7. // ui->tableView->update();
    8. ui->tableView->setFocus(); // add this
    9. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by norobro; 19th August 2011 at 02:43. Reason: comment out update() line

  7. #7
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: TableView ProxyModel problem

    That looks like it works!!! I didn't think about setting the focus....Not sure why it needed that but it works. Now to get it to work in my code!

    Thanks a million!

  8. #8
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: TableView ProxyModel problem

    Works great! I had to modify it a bit for my application, but you got me in the right direction!!! Many thanks!!!

Similar Threads

  1. Custom ProxyModel or Two Sync'd Models ?
    By SSurgnier in forum Qt Programming
    Replies: 2
    Last Post: 2nd August 2011, 18:44
  2. Dragging out of a QTreeView with a ProxyModel
    By jmichiel in forum Newbie
    Replies: 4
    Last Post: 19th June 2011, 19:04
  3. ProxyModel problem
    By waynew in forum Qt Programming
    Replies: 1
    Last Post: 14th February 2010, 06:40
  4. Replies: 2
    Last Post: 6th January 2009, 20:55
  5. tableView Problem
    By hrcariaga in forum Newbie
    Replies: 5
    Last Post: 7th February 2008, 08:29

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.