Results 1 to 3 of 3

Thread: QListWidget Deselect

  1. #1
    Join Date
    Sep 2008
    Location
    St. Louis, MO
    Posts
    19
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QListWidget Deselect

    Can QListWidget be made to allow at most one selected item? In other words, I need to create a list that can have 0 or 1 item selected. Clicking on a selected item deselects that item resulting in the selected items count to be 0.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QListWidget Deselect

    I'm afraid there is no property you could just turn on. Perhaps the easiest (or least code) would be to override mousePressEvent(), create a copy of the QMouseEvent object so that control modifier is turned on, and pass it to the base class implementation. Then it would probably work in SingleSelection mode the way you want.
    J-P Nurmi

  3. #3
    Join Date
    Sep 2008
    Location
    St. Louis, MO
    Posts
    19
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QListWidget Deselect

    Thanks JPN for your quick reply. I was able to achieve the desired effect by connecting to the QListWidget::itemClicked signal. Here's an example of the kind of SLOT function I wrote:

    Qt Code:
    1. void MyClass::listItemClicked( QListWidgetItem *item )
    2. {
    3. if ( previousSelection != NULL ) {
    4. if ( item->text().operator==( previousSelection->text() ) ) {
    5. previousSelection = NULL;
    6. molList->clearSelection();
    7. molList->clearFocus();
    8. return;
    9. }
    10. }
    11.  
    12. previousSelection = item;
    13. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Segmentation Faul using addItem (QListWidget)
    By gnusar in forum Qt Programming
    Replies: 3
    Last Post: 8th November 2008, 09:27
  2. how to sync a QTreeWidget and a QListWidget?
    By zl2k in forum Qt Programming
    Replies: 2
    Last Post: 5th September 2008, 20:55
  3. QListWidget Problem
    By pmabie in forum Qt Programming
    Replies: 1
    Last Post: 7th October 2007, 06:52
  4. Replies: 13
    Last Post: 15th December 2006, 11:52
  5. keypress while editing an item in QListWidget
    By Beluvius in forum Qt Programming
    Replies: 3
    Last Post: 4th April 2006, 09:56

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.