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. How to physically deselect a QListWidgetItem under Linux

How to physically deselect a QListWidgetItem under Linux

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 998 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.
  • JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by
    #1

    This may be a question about how to use the Linux UI, not just a Qt issue!

    Qt5. Ubuntu 18.04, which uses GNOME desktop if that's relevant.

    I have a plain, default QListWidget, single-selection. It starts life with an item (QListWidgetItem) selected, shown with dark blue background.

    Now, I/my user wants to deselect that item, and have nothing selected. So using my Windows know-how, I go Ctrl+click on the selected item. Its dark-blue background disappears, it now shows with a light-blue background. Maybe indicating "focus", I don't know.

    But QListWidget::currentRow is still the old selected row, and QListWidget::currentItem is still there....

    Am I doing the wrong key press, assuming it works like Windows? (Tried Googling, no help.) Or, am I misunderstanding, is "current row" != "selected row"?

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      The current and the selected index are independently from each other. Ctrl+Click imo only deselects the item(s) but does not remove the current index. If you want to reset the current index you have to do call setCurrentIndex(QModelIndex())

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      JonBJ 1 Reply Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        The current and the selected index are independently from each other. Ctrl+Click imo only deselects the item(s) but does not remove the current index. If you want to reset the current index you have to do call setCurrentIndex(QModelIndex())

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @Christian-Ehrlicher
        Ohhhh.

        That's not at all what I'm trying to achieve. All I'm doing is having a button which acts on whatever the user has "selected" in the UI, by having clicked on it, and it turns dark blue. And the user should be able to "unselect" that by Ctrl+Click. Absolutely standard stuff.

        Now, I thought I was supposed to do that by looking at the current item (e.g. QListWidget::currentRow). I thought that meant the dark blue one.

        But from what you're saying, does my/the user's idea of "current" item actually correspond to Qt's selected item instead?

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          I think yes. The current one is rendered with a small focus rect and can only be exactly one item.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          JonBJ 1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            I think yes. The current one is rendered with a small focus rect and can only be exactly one item.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @Christian-Ehrlicher
            I will re-investigate.

            In that case, I think I understand what Qt's "selected" item(s) is(are), what does it (a QListWidget at least) use a "current" item for?

            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