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. After clearing selection, the last selected item is still selected

After clearing selection, the last selected item is still selected

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 1.2k 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.
  • M Offline
    M Offline
    Moschops
    wrote on last edited by VRonin
    #1

    I have a tree view.

    I needed some cleverness in what was selected when the user clicked on various parts of it.

    There is a way to click in the treeview that causes the selection model to be cleared. That is, the following code is called:

    selectionModel->clearSelection();

    Immediately after this, the row that was previously highlighted with a blue background no longer has a blue background. However, it still has a dotted outline, and when the selection is fetched

    model->selectedRows()

    that row is still selected. Where my code is currently doing this:
    selectionModel->clearSelection();
    I want to actually clear the selection. I want there to be nothing selected. I'm sure that's what clearSelection is meant to do, so what's with the dotted outline and why is that row still selected?

    1 Reply Last reply
    0
    • L Offline
      L Offline
      LauraB
      wrote on last edited by
      #2

      This reply happens a little late, I know, but I stumbled upon the same problematic today and I think I figured it out. I guess other people can also have the same issue, so I allow myself to reply to this very old topic :

      I understood it all after reading this : http://doc.qt.io/qt-5/model-view-programming.html#handling-selections-in-item-views

      To summarize, regarding our issue which is even if we clear selection we still have a dotted outline on the item, it's because "selected" item and "current" item are two differents states in Qt.

      Unless the selection mode on your model/view is NoSelection, when you set an item as current you also set it as selected (by clicking on it or by calling setCurrentIndex() ).
      However, after clearSelection(), you only set the "selected" state to false, but this item is still your "current" item.

      The solution I found for this is to call setCurrentIndex() and pass to it an invalid index.

      Hope this helps for people who had the same problem.

      Regards,

      Laura B.

      VRoninV 1 Reply Last reply
      0
      • L LauraB

        This reply happens a little late, I know, but I stumbled upon the same problematic today and I think I figured it out. I guess other people can also have the same issue, so I allow myself to reply to this very old topic :

        I understood it all after reading this : http://doc.qt.io/qt-5/model-view-programming.html#handling-selections-in-item-views

        To summarize, regarding our issue which is even if we clear selection we still have a dotted outline on the item, it's because "selected" item and "current" item are two differents states in Qt.

        Unless the selection mode on your model/view is NoSelection, when you set an item as current you also set it as selected (by clicking on it or by calling setCurrentIndex() ).
        However, after clearSelection(), you only set the "selected" state to false, but this item is still your "current" item.

        The solution I found for this is to call setCurrentIndex() and pass to it an invalid index.

        Hope this helps for people who had the same problem.

        Regards,

        Laura B.

        VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        @LauraB said in After clearing selection, the last selected item is still selected:

        when you set an item as current you also set it as selected

        Not necessarily.

        1. select item 1 (selection = {item 1}, currentIndex = item 1)
        2. ctrl+select item 2 (selection = {item 1,item 2}, currentIndex = item 2)
        3. ctrl+deselect item 1 (selection = {item 2}, currentIndex = item 1)

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        1

        • Login

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