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. Get text of QTreeWidgetItem

Get text of QTreeWidgetItem

Scheduled Pinned Locked Moved General and Desktop
3 Posts 1 Posters 6.2k 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.
  • R Offline
    R Offline
    rotpar
    wrote on last edited by
    #1

    Hi,

    By adding more then one Item to the tree, the program is not able to find the text of the 2nd, 3rd,... Item. The QString I try to get stays empty
    I'm creating a QTreeWidgetItems and add them to a QTreeWidget in a QDockWidget called "targetInfoWidget_".

    @
    bool ok;
    QString text = QInputDialog::getText(this, tr("QInputDialog::getText()"),
    tr("Target Name:"), QLineEdit::Normal, "", &ok);
    if (ok && !text.isEmpty()) {
    QTreeWidgetItem *item = new QTreeWidgetItem(targetInfoWidget_->treeWidget);
    item->setText(0, text);
    }
    @

    and then I want to get the selected item in the tree and do stuff with it, depending on the found name of the item.

    @
    QTreeWidgetItem *item = targetInfoWidget_->treeWidget->currentItem();
    int col = targetInfoWidget_->treeWidget->indexOfTopLevelItem(item);
    QMessageBox::critical(this, "Col", QString::number(col));
    QString itemToAppendName = item->text(col);
    QMessageBox::critical(this, "item To Append", itemToAppendName);
    @

    The QMessageBoxes are for me to check what the results of the lines are and to get to know at which line the results are not correct anymore.
    Everything works with the first Item. It returns the right column and the right item text. But with a 2nd item the right column is returned, but the QString stays empty. I don't know what I'm doing wrong.

    1 Reply Last reply
    0
    • R Offline
      R Offline
      rotpar
      wrote on last edited by
      #2

      Hi again,

      uhm... after googling for days, I still can't find a solution.

      This is how it looks:
      !http://s7.directupload.net/images/130731/lusn7czx.png(picture)!

      For the item asd the messages return "0" and "asd". For the Item sdf the messages return "1" and what is shown in picture.

      Is no one out there who can help me? Or do you need more Code or other informations? Any suggestion might help :/.

      Thanks alot.

      1 Reply Last reply
      0
      • R Offline
        R Offline
        rotpar
        wrote on last edited by
        #3

        bq. You have to get the item's text from column 0, and index 1.
        @QTreeWidgetItem *item = targetInfoWidget_->treeWidget->currentItem();
        int index = targetInfoWidget_->treeWidget->indexOfTopLevelItem(item);
        QMessageBox::critical(this, "Col", QString::number(index));
        QString itemToAppendName = item->text(0);
        QMessageBox::critical(this, "item To Append", itemToAppendName);@

        now it works

        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