Results 1 to 9 of 9

Thread: Method selectAll() from QListView does not work properly

  1. #1
    Join Date
    Aug 2010
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Method selectAll() from QListView does not work properly

    It's my first post here, so I would say hello to you!

    I've got problem with QListView and QFileSystemModel. I've created a model:

    Qt Code:
    1. model = new QFileSystemModel;
    2. model->setRootPath(QDir::currentPath());
    To copy to clipboard, switch view to plain text mode 

    and connected it with listView:

    Qt Code:
    1. ui->listView->setModel(model);
    2. ui->listView->setRootIndex(model->index(tr("/home/lukasz/")));
    To copy to clipboard, switch view to plain text mode 

    Everything works good but one thing: selecting all of items. When I click ctrl+a, or invoke method selectAll():
    Qt Code:
    1. ui->listView->selectAll();
    To copy to clipboard, switch view to plain text mode 

    method ui->listView->selectionModel()->selectedIndexes() returns number of highlighted files multipled by four. For example when I select manually all, four items, method selectedIndexes() returns number 4. But when I click ctrl+a or invoke selectAll(), selectedIndexes() returns 16.
    I tried compiling on linux and on windows too - results are the same.
    Here is a very simple project created with Qt Creator: link. It should help you, if solution of my problem isn't simple.

    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Method selectAll() from QListView does not work properly

    Use selectedRows() and you get what you want. With selectedIndexes() you get all selected indexes and since your model has 4 columns (put it in a QTableView or QTreeView and you will see) you always get the x4.

  3. #3
    Join Date
    Aug 2010
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Method selectAll() from QListView does not work properly

    Thanks for response. So only elegant way to do this is create new, custom model? If I use selectedRows(), it works properly only with selectAll() method (selecting manually items does not work)

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Method selectAll() from QListView does not work properly

    Quote Originally Posted by Treadstone View Post
    So only elegant way to do this is create new, custom model?
    No, all works well with Qt stuff. And the model has nothing to do with the selection.
    If I use selectedRows(), it works properly only with selectAll() method (selecting manually items does not work)
    what does not work exactely? Are you displaying all columns? Also you might want use proper selectionBehavior and selectionMode settings. (Or you can remove the non needed columns from the model.)

  5. #5
    Join Date
    Aug 2010
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Method selectAll() from QListView does not work properly

    Sorry, I didn't unterstood it very well, but now everything with selecting behavior is clear. Could you easily explain me how to remove columns in that model?

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Method selectAll() from QListView does not work properly

    Use QAbstractItemModel::removeColumn() to remove non needed columns. It will save memory and provides better performance.

  7. #7
    Join Date
    Aug 2010
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Method selectAll() from QListView does not work properly

    I dont know how to use it; especially what to give as a second argument, QModelIndex. I'm pretty sure it cant be be a single item from the model, but dont have any ideas. Can you explain me it a bit more accurately or simply write a small piece of code which will remove single column?

    thanks in advance

  8. #8
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Method selectAll() from QListView does not work properly

    I see right know that QFileSystemModel does not reimp removecolumns, so you can't use it. Then you have to use the selection options.

  9. The following user says thank you to Lykurg for this useful post:

    Treadstone (19th August 2010)

  10. #9
    Join Date
    Aug 2010
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Method selectAll() from QListView does not work properly

    Thanks, used selectedRows() and it's working fine

    Regards

Similar Threads

  1. selectAll in QLineEdit does not work
    By Ishmael in forum Newbie
    Replies: 4
    Last Post: 25th May 2015, 05:26
  2. QGraphicsView::scale does not work properly.
    By metdos in forum Qt Programming
    Replies: 1
    Last Post: 18th January 2010, 08:58
  3. QT's style sheet does not work properly on Mac OS X
    By sanjayshelke in forum Qt Programming
    Replies: 1
    Last Post: 10th December 2009, 10:50
  4. QLineF::intersect does not work properly (solved)
    By jano_alex_es in forum Newbie
    Replies: 1
    Last Post: 23rd June 2009, 09:06
  5. Why can't I make dynamic_cast work properly?
    By pir in forum General Programming
    Replies: 13
    Last Post: 18th July 2006, 16:17

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.