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. [SOLVED] How to get selected item on QTreeView ?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] How to get selected item on QTreeView ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtreeview
9 Posts 4 Posters 35.5k 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.
  • T Offline
    T Offline
    takoo
    wrote on 13 Feb 2016, 19:19 last edited by takoo
    #1

    How to get selected item on QTreeView ?

    T 1 Reply Last reply 14 Feb 2016, 14:49
    0
    • N Offline
      N Offline
      Ni.Sumi
      wrote on 13 Feb 2016, 21:16 last edited by
      #2

      Hi @takoo

      Is some thing this, you are talking.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        asanka424
        wrote on 13 Feb 2016, 21:30 last edited by
        #3

        currentIndex() doesn't work?

        1 Reply Last reply
        1
        • T Offline
          T Offline
          takoo
          wrote on 13 Feb 2016, 21:55 last edited by
          #4

          Please give me example code

          K 1 Reply Last reply 13 Feb 2016, 22:13
          0
          • N Offline
            N Offline
            Ni.Sumi
            wrote on 13 Feb 2016, 22:05 last edited by Ni.Sumi
            #5

            Hi @takoo ,
            connect(treeWidgetName, SIGNAL(itemSelectionChanged()), this, SLOT(mySlot_Changed()));

            or

            connect(this,SIGNAL(itemClicked(QTreeWidgetItem*, int)), SLOT((mySlot_Changed()));

            http://doc.qt.io/qt-4.8/qtreewidget.html#itemSelectionChanged

            1 Reply Last reply
            0
            • T takoo
              13 Feb 2016, 21:55

              Please give me example code

              K Offline
              K Offline
              kshegunov
              Moderators
              wrote on 13 Feb 2016, 22:13 last edited by kshegunov
              #6

              @takoo
              Hello,
              As @asanka424 suggested, use the available API for the view and the model:

              QTreeView * view; //< You have that properly set, I'm putting it here for completeness.
              QModelIndex index = view->currentIndex();
              QVariant data = view->model()->data(index);
              QString text = data.toString();
              

              Kind regards.

              Read and abide by the Qt Code of Conduct

              1 Reply Last reply
              1
              • A Offline
                A Offline
                asanka424
                wrote on 14 Feb 2016, 02:47 last edited by
                #7

                If you want to get the item use QModelIndex::internalPointer()

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  takoo
                  wrote on 14 Feb 2016, 14:04 last edited by
                  #8

                  @kshegunov thanks :D

                  1 Reply Last reply
                  0
                  • T takoo
                    13 Feb 2016, 19:19

                    How to get selected item on QTreeView ?

                    T Offline
                    T Offline
                    takoo
                    wrote on 14 Feb 2016, 14:49 last edited by
                    #9
                    This post is deleted!
                    1 Reply Last reply
                    0

                    5/9

                    13 Feb 2016, 22:05

                    • Login

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