Results 1 to 2 of 2

Thread: Question about selecting all items in a QListWidget

  1. #1
    Join Date
    Jan 2006
    Posts
    105
    Thanks
    38
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Thumbs up Question about selecting all items in a QListWidget

    Hi all, I have a QListWidget and I have connected a button "clicked" signal to a slot where I need to select all the items in the list. This is the code that I use:
    Qt Code:
    1. void MyPage::selectAll()
    2. {
    3. int n = list -> count();
    4.  
    5. if ((list -> selectedItems()).count() == n) return;
    6.  
    7. for (int i = 0; i < n; i++)
    8. list -> setItemSelected(list -> item(i), true);
    9. }
    To copy to clipboard, switch view to plain text mode 
    I want to know if there's some other way to do this more eficiently, without having to go through all the items in the list, using QListWidget::selectedItems() maybe?

    Thanks.
    Last edited by Dark_Tower; 7th April 2006 at 12:11.

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Question about selecting all items in a QListWidget

    try list->selectAll()

  3. The following user says thank you to munna for this useful post:

    Dark_Tower (7th April 2006)

Similar Threads

  1. How to make QListWidget items editable?
    By montylee in forum Qt Programming
    Replies: 14
    Last Post: 3rd October 2008, 10:57
  2. Replies: 1
    Last Post: 6th September 2008, 00:54
  3. Get Visible Items from the QListWidget
    By srj in forum Qt Programming
    Replies: 4
    Last Post: 22nd November 2006, 21:13
  4. Qt 4.2: QListWidget changes size of its items
    By KingFish in forum Qt Programming
    Replies: 2
    Last Post: 25th October 2006, 12:06
  5. [Qt4]: Adding centered items in QListWidget
    By Jojo in forum Qt Programming
    Replies: 4
    Last Post: 16th March 2006, 21:04

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.