Dselect QListWidget item
-
hi
im for some reason using qt 5.12 in c++ environment.
i want to perform deselection:
ui->myList->setCurrentItem(nullptr); ui->myList->clearSelection();
works perfect when i connect it to a button; but i cant do this via mouse click event
i have a QListWidget and despite searching, i have these problems:
- i want to trigger deselect when i click empty space within the QListWidget and when clicking outside of QListWidget
- when QListWidget is filled, an item is auto selected, how can i avoid this?
- how can i appen empty space at the end of QListWidget?
-
Ad 1:
To recognise a mouse press in an empty area, install an event filter and handleQEvent::MouseButtonPress
. Pass the mouse event's point toitemAt()
and clear the selection, if it returnsnullptr
.
You can do the same withQEvent::FocusOut
, to handle a click outside the list view. Mind that this may not work, in case the list widget is a focus proxy (it isn't by default).Ad 2:
The list view is populated programmatically. Just callclearSelection()
when this has been done.Ad 3:
Read the height after the list widget has been populated. Add the desired height margin and useQWidget::setMinimumHeight()
. -
-
whatever i did, i couldn't implement
QEvent::MouseButtonPress
and read empty space in event filter of aQListWidget
; resorting toQListView
however solved my problem. -
what i really needed was
setCurrentItem(nullptr)
-
setMinimumHeight
(at least for QListView ) changes the pane's proportions; i want to add empty area within the pane so the extra space is added for scrolling.
-