Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Dselect QListWidget item
Forum Updated to NodeBB v4.3 + New Features

Dselect QListWidget item

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 93 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    QTNewb
    wrote last edited by
    #1

    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:

    1. i want to trigger deselect when i click empty space within the QListWidget and when clicking outside of QListWidget
    2. when QListWidget is filled, an item is auto selected, how can i avoid this?
    3. how can i appen empty space at the end of QListWidget?
    1 Reply Last reply
    0
    • Axel SpoerlA Offline
      Axel SpoerlA Offline
      Axel Spoerl
      Moderators
      wrote last edited by
      #2

      Ad 1:
      To recognise a mouse press in an empty area, install an event filter and handle QEvent::MouseButtonPress. Pass the mouse event's point to itemAt() and clear the selection, if it returns nullptr.
      You can do the same with QEvent::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 call clearSelection() when this has been done.

      Ad 3:
      Read the height after the list widget has been populated. Add the desired height margin and use QWidget::setMinimumHeight().

      Software Engineer
      The Qt Company, Oslo

      1 Reply Last reply
      2
      • Q Offline
        Q Offline
        QTNewb
        wrote last edited by QTNewb
        #3

        @Axel-Spoerl

        1. whatever i did, i couldn't implement QEvent::MouseButtonPress and read empty space in event filter of a QListWidget; resorting to QListView however solved my problem.

        2. what i really needed was setCurrentItem(nullptr)

        3. 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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved