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 ?

[SOLVED] How to get selected item on QTreeView ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtreeview
9 Posts 4 Posters 35.4k Views
  • 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 last edited by takoo
    #1

    How to get selected item on QTreeView ?

    T 1 Reply Last reply
    0
    • Ni.SumiN Offline
      Ni.SumiN Offline
      Ni.Sumi
      wrote on 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 last edited by
        #3

        currentIndex() doesn't work?

        1 Reply Last reply
        1
        • T Offline
          T Offline
          takoo
          wrote on last edited by
          #4

          Please give me example code

          kshegunovK 1 Reply Last reply
          0
          • Ni.SumiN Offline
            Ni.SumiN Offline
            Ni.Sumi
            wrote on 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

              Please give me example code

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on 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 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 last edited by
                  #8

                  @kshegunov thanks :D

                  1 Reply Last reply
                  0
                  • T takoo

                    How to get selected item on QTreeView ?

                    T Offline
                    T Offline
                    takoo
                    wrote on last edited by
                    #9
                    This post is deleted!
                    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