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.
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.
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
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:
{ if ( previousSelection != NULL ) { if ( item->text().operator==( previousSelection->text() ) ) { previousSelection = NULL; molList->clearSelection(); molList->clearFocus(); return; } } previousSelection = item; }To copy to clipboard, switch view to plain text mode
Bookmarks