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 check if no treeitem is selected in the tree view
Forum Updated to NodeBB v4.3 + New Features

How to check if no treeitem is selected in the tree view

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 953 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.
  • S Offline
    S Offline
    summit
    wrote on last edited by
    #1

    This is how i get the selected item in the tree view.

    QModelIndex index = currentTreeView->selectionModel()->currentIndex();
    

    How would i get to know if no item is selected in the tree view.

    JonBJ 1 Reply Last reply
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by
      #2

      Assuming a QTreeView, I believe selectionModel() is not relevant. The inherited abstract class contains direct access to currentIndex() and the returned object contains status methods for the index.

      1 Reply Last reply
      0
      • S summit

        This is how i get the selected item in the tree view.

        QModelIndex index = currentTreeView->selectionModel()->currentIndex();
        

        How would i get to know if no item is selected in the tree view.

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

        @summit
        @Kent-Dorfman may know more than I, but be careful: in Qt current items are not necessarily the same as selected items....

        You can try his way. For my part I would first have looked at currentTreeView->selectionModel()->selectedIndexes().count() == 0, or directly from currentTreeView->selectedIndexes().count() == 0.

        Christian EhrlicherC 1 Reply Last reply
        3
        • JonBJ JonB

          @summit
          @Kent-Dorfman may know more than I, but be careful: in Qt current items are not necessarily the same as selected items....

          You can try his way. For my part I would first have looked at currentTreeView->selectionModel()->selectedIndexes().count() == 0, or directly from currentTreeView->selectedIndexes().count() == 0.

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @JonB said in How to check if no treeitem is selected in the tree view:

          in Qt current items are not necessarily the same as selected items....

          correct, and it's also explained in the docs: https://doc.qt.io/qt-5/model-view-programming.html#current-item-and-selected-items

          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
          2
          • Christian EhrlicherC Christian Ehrlicher

            @JonB said in How to check if no treeitem is selected in the tree view:

            in Qt current items are not necessarily the same as selected items....

            correct, and it's also explained in the docs: https://doc.qt.io/qt-5/model-view-programming.html#current-item-and-selected-items

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

            @Christian-Ehrlicher
            Oh, excellenty to the reference! Current item and selected items Is that subsection new in the docs, in the past I didn't find that explanation?

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

              @JonB said in How to check if no treeitem is selected in the tree view:

              Is that subsection new in the docs, in the past I didn't find that explanation?

              It's already there since some years... :)
              https://doc.qt.io/archives/qt-4.8/model-view-programming.html

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

              1 Reply Last reply
              3

              • Login

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