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. QListView. Unselect item.
Forum Updated to NodeBB v4.3 + New Features

QListView. Unselect item.

Scheduled Pinned Locked Moved General and Desktop
13 Posts 5 Posters 17.3k 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.
  • A Offline
    A Offline
    andre
    wrote on last edited by
    #4

    Well, sel.isEmpty() on line 9 is true, then you don't actually have selected items, do you?

    So what is it you want to reset, exactly?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chiz_
      wrote on last edited by
      #5

      [quote author="Andre" date="1295347918"]Well, sel.isEmpty() on line 9 is true, then you don't actually have selected items, do you?

      So what is it you want to reset, exactly? [/quote]

      Method "selectionChanged" doesn't arise at all. So there is no matter what is inside method :-)

      I solve my problem, but I don't like the way I did it. I set selectionMode from SingleSelection to ExtendedSelection. I don't like that user can select more then one item, but so far I can't achive unselecting.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #6

        Which selection mode do you have set on your list view?

        bq. QAbstractItemView::SingleSelection:
        When the user selects an item, any already-selected item becomes unselected, and the user cannot unselect the selected item by clicking on it.

        With single selection, you could subclass QListView, reimplement mousePressEvent, check if the mouse press was on a valid index (continue with the base class implementation) or not (clear the selection model and stop).

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Chiz_
          wrote on last edited by
          #7

          [quote author="Volker" date="1295352652"]Which selection mode do you have set on your list view?

          bq. QAbstractItemView::SingleSelection:
          When the user selects an item, any already-selected item becomes unselected, and the user cannot unselect the selected item by clicking on it.

          With single selection, you could subclass QListView, reimplement mousePressEvent, check if the mouse press was on a valid index (continue with the base class implementation) or not (clear the selection model and stop).[/quote]

          Wow! Thanks a lot!
          I just need QAbstractItemView::ContiguousSelection selection mode.

          1 Reply Last reply
          0
          • I Offline
            I Offline
            ivan.todorovich
            wrote on last edited by
            #8

            There's currently an active "Jira Ticket":http://bugreports.qt.nokia.com/browse/QTBUG-8836 on this issue.
            Since there's no way to interactively deselect item. You should take a look at it and vote if you are interested.

            o_o Sorry for my rusted english.

            1 Reply Last reply
            0
            • C Offline
              C Offline
              Chiz_
              wrote on last edited by
              #9

              [quote author="ivan.todorovich" date="1295444078"]There's currently an active "Jira Ticket":http://bugreports.qt.nokia.com/browse/QTBUG-8836 on this issue.
              Since there's no way to interactively deselect item. You should take a look at it and vote if you are interested.[/quote]

              It explains everything. Thanks a lot. I'll be tracking this bug.

              1 Reply Last reply
              0
              • D Offline
                D Offline
                dangelog
                wrote on last edited by
                #10

                [quote author="Chiz_" date="1295271468"]I have QListView widget. It have some items.
                When I click on an item I show details about this item. Everything is good so far.
                If I click another item, details of clicked element is shown. Everything is perfect so far.
                For such behavior I use clicked(QModelIndex) signal in QListView.
                Question: how to UNSELECT item? I want to click on empty area of QListView and hide details. Problem is that signal clicked(QModelIndex) is not invoked/called.[/quote]

                How about subclassing and using something like this in your mousePressEvent?
                @
                QModelIndex index = indexAt(event->pos());
                if (index.isValid()) {
                selectionModel()->select(index, QItemSelectionModel::ClearAndSelect);
                } else {
                clearSelection();
                }
                @

                Software Engineer
                KDAB (UK) Ltd., a KDAB Group company

                1 Reply Last reply
                0
                • I Offline
                  I Offline
                  ivan.todorovich
                  wrote on last edited by
                  #11

                  reimplement mouseReleaseEvent instead of mousePress, since the 'click' happens when you release the mouse.

                  o_o Sorry for my rusted english.

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    goetz
                    wrote on last edited by
                    #12

                    As far as I know this is platform dependent. On a Mac the selction changes as soon as you press the mouse button. On windows it might be not until button release.

                    http://www.catb.org/~esr/faqs/smart-questions.html

                    1 Reply Last reply
                    0
                    • C Offline
                      C Offline
                      Chiz_
                      wrote on last edited by
                      #13

                      [quote author="Volker" date="1295554550"]As far as I know this is platform dependent. On a Mac the selction changes as soon as you press the mouse button. On windows it might be not until button release.[/quote]

                      Thanks for such information. I'm developing on WinXP for Linux :-)

                      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