Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved problem to show the selected item in a QTreeWidget

    General and Desktop
    2
    4
    520
    Loading More Posts
    • 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.
    • Z
      Zunneh last edited by

      Hi guys , i have a problem , i 'm working in a big project and i want to see the selected item i a QTreeWidget to display it in a QTextEdit , so i created a new program (there are only QTreeWidget and some items ) and tested it and it work perfectly , now when i writed the function in the big project , it didn't work (it work but not correct) , in my small program i can see the item selected (see the screen )

      this is the function that i use and it work perfectly

      QObject::connect(ui->treeWidget,&QTreeWidget::itemSelectionChanged,ui->textEdit,[this]()->void{
      
      QString test,e;
      
      test=ui->treeWidget->currentItem()->text(ui->treeWidget->currentColumn());
      ui->textEdit->setText(test);
      });
      

      0_1552143077687_Capture d’écran 2019-03-09 à 15.50.30.png
      P.S : we can see it work perfect, Lyon is selected and displayed in the qtexEdit and when i change the selection the QtextEdit change

      now this is the screen from my big project which i use the same function

      0_1552143160024_53902770_350782289113099_6652509006944272384_n.png

      her Aide is empty
      the problem is , in my this program he detect when i change the selection but he always read the QString test as empty (" " ) when i initialize Aide for exemple (" Hello world ") and click in any item , it became empty , so he always read the item selection as empty , when i put the QTextEdit->setText("hello") and click in any item , it work perfectly , hello is displayed , but when writing QTextEdit->setText(test) , its always empty, do you have any idea why he don't read the item name perfectly , why the item read is always empty but really it must be the text selected ?? thanks

      my english is average, please use simple words and try to be the most explicit, thank you

      1 Reply Last reply Reply Quote 0
      • Christian Ehrlicher
        Christian Ehrlicher Lifetime Qt Champion last edited by

        QTreeWidget::itemSelectionChanged() is emitted when the selection changed which does not mean that the current index changed. For this you should use QTreeWidget::currentItemChanged()
        You should also see when you compare the output of currentItem() and QTreeWidget::selectedItems()

        Qt has to stay free or it will die.

        Z 1 Reply Last reply Reply Quote 3
        • Z
          Zunneh @Christian Ehrlicher last edited by

          @Christian-Ehrlicher the Signal works perfectly , i have a problem with the slot , he don't read the selection item correctly , he read it always empty

          my english is average, please use simple words and try to be the most explicit, thank you

          1 Reply Last reply Reply Quote 0
          • Christian Ehrlicher
            Christian Ehrlicher Lifetime Qt Champion last edited by

            As I said before - current item and selected item are two different things so itemSelectionChanged() is emitted when the selection changed, currentItemChanged when the current index changes. Since you're looking fot the current column you have to look for currentItemChanged ...

            Qt has to stay free or it will die.

            1 Reply Last reply Reply Quote 2
            • First post
              Last post