Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. [Solved] Qt - How to select item in tree widget?
Forum Updated to NodeBB v4.3 + New Features

[Solved] Qt - How to select item in tree widget?

Scheduled Pinned Locked Moved Language Bindings
5 Posts 2 Posters 5.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.
  • N Offline
    N Offline
    needhelp_gh
    wrote on last edited by
    #1

    Hi,

    I was trying to write code that selects an item in a tree if it exists.

    Here is what I have so far:

    @if a != "":
    item = QtGui.QTreeWidgetItem(tree)
    item.setText(0, a)
    tree.setCurrentItem(item)@

    but this seems to just add it to the tree & select it. I just want it to select the item if it exists in the tree not re-add it. Help!!

    Thanks!!

    [Moved: because this forum is right place for python questions /Vass]


    http://abstrusegoose.com/432

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      [quote author="needhelp_gh" date="1337695981"]Hi,
      I just want it to select the item if it exists in the tree not re-add it.
      [/quote]

      But that's exactly what you implemented.

      if you want to search for an item, you have to do something like this (this is C++):

      @
      if (a != "")
      {
      QTreeWidget* pTree = ...; // this is your tree widget pointer
      QList<QTreeWidgetItem *> itemList = pTree->findItems(a);
      if(!itemList.isEmpty())
      // ...
      }
      @

      written directly from brain, not tested

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • N Offline
        N Offline
        needhelp_gh
        wrote on last edited by
        #3

        Yeah, that was the only way I thought could work.

        I'll try searching for the item like you say & then setting it to current item.

        Thanks!!

        (I'll get back with code if it works out for people who might need it in the future.)


        http://abstrusegoose.com/432

        1 Reply Last reply
        0
        • N Offline
          N Offline
          needhelp_gh
          wrote on last edited by
          #4

          Seems to be missing some parameters for:

          @QList<QTreeWidgetItem *> itemList = pTree->findItems(a);@

          I'm not sure about the Qt::MatchFlags parameter..


          http://abstrusegoose.com/432

          1 Reply Last reply
          0
          • N Offline
            N Offline
            needhelp_gh
            wrote on last edited by
            #5

            Nvm, got it:
            @
            if a != "":
            list = tree2.findItems(a, QtCore.Qt.MatchExactly, 0)
            for i in list:
            tree2.setCurrentItem(i)@

            Hope that helps for anyone else!! :)


            http://abstrusegoose.com/432

            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