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. QTreeWidget: figure out all possible celection methods
Forum Update on Monday, May 27th 2025

QTreeWidget: figure out all possible celection methods

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 798 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.
  • B Offline
    B Offline
    Bremenpl
    wrote on last edited by
    #1

    Hello there,
    In order to find the index (int) of the item selected by click in the QTreeWidget I used itemClicked signal. I have a problem however. I noticed that user can select an item, and with the left button clicked swing through the items in the view. The item that ones unclicks the mouse at becomes selected. But in that case no signal is generated, at least I cannot figure out which one. I would really appreciate all help in this matter.

    lprzenioslo.zut.edu.pl

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You should rather use the QItemSelectionModel::selectionChanged signal from your QTreeWidget selection model.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Bremenpl
        wrote on last edited by
        #3

        But is it possible to retrieve selected column and text from this model? For clicked item i get a QTreeWidgetItem, so I do:

        /*!
         * \brief CItemsMenu::on_twItems_itemClicked: Find index of selected item in this slot
         * \param item
         * \param column
         */
        void CItemsMenu::on_twItems_itemClicked(QTreeWidgetItem *item, int column)
        {
            // get selected item text
            QString itemText = item->text(column);
        
            QTreeWidgetItemIterator it(mp_tw);
            int index = 0;
        
            while (*it)
            {
                if ((*it)->text(column) == itemText)
                {
                    // item found, update global index
                    m_currentItem = index;
        
                    //CBcLogger::instance()->print(MLL::ELogLevel::LDebug)
                            //<< "Item index changed by click: " << m_currentItem;
                    return;
                }
        
                ++it;
                ++index;
            }
        
            //CBcLogger::instance()->print(MLL::ELogLevel::LWarning)
                    //<< "Item index not found by click!";
        }
        

        lprzenioslo.zut.edu.pl

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You get the indexes matching selection/deselection from there you can get the items from the tree.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2

          • Login

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