Results 1 to 10 of 10

Thread: How to set selected item of a QListWidget?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2008
    Location
    Qt Reference Documentation
    Posts
    62
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    25
    Thanked 4 Times in 4 Posts

    Default Re: How to set selected item of a QListWidget?

    well, I tried this one:
    Qt Code:
    1. QListWidget *list = new QListWidget();
    2. list->setSelectionMode(QAbstractItemView::SingleSelection);
    3.  
    4. QModelIndex modelIndex = list->rootIndex(); // u have to find the model index of the first item here
    5. list->setCurrentIndex(modelIndex);
    To copy to clipboard, switch view to plain text mode 

    but it didn't work, so I am gonna stick with this one for now:
    Qt Code:
    1. listWidget->item(0)->setSelected(true);
    To copy to clipboard, switch view to plain text mode 

    and I'll try to read the model-view-introduction sometimes later...


    Thanks for your help.

  2. #2
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    21
    Thanked 66 Times in 62 Posts

    Default Re: How to set selected item of a QListWidget?

    I don't think he could have gotten scared of 4 lines of code wrote it just to motivate him to read abt mvc..thats not wrong i guess..and it's not working cuz of the model index..I guess I should hv saved myself all the trouble & wrote ur one line example..but that's how it is

Similar Threads

  1. How to get parent of selected item in TreeView?
    By RavenS in forum Qt Programming
    Replies: 2
    Last Post: 7th March 2009, 14:27
  2. Changing selected item color in non-current window.
    By Doug Broadwell in forum Qt Programming
    Replies: 1
    Last Post: 26th August 2007, 08:09
  3. QTreeView: selection behavior upon selected item removal
    By Pieter from Belgium in forum Qt Programming
    Replies: 6
    Last Post: 11th July 2007, 17:00
  4. Replies: 1
    Last Post: 19th April 2007, 23:23
  5. keypress while editing an item in QListWidget
    By Beluvius in forum Qt Programming
    Replies: 3
    Last Post: 4th April 2006, 10:56

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
  •  
Qt is a trademark of The Qt Company.