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. problem to show the selected item in a QTreeWidget
QtWS25 Last Chance

problem to show the selected item in a QTreeWidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.1k 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.
  • Z Offline
    Z Offline
    Zunneh
    wrote on last edited by
    #1

    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
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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 Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      Z 1 Reply Last reply
      3
      • Christian EhrlicherC Christian Ehrlicher

        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()

        Z Offline
        Z Offline
        Zunneh
        wrote on last edited by
        #3

        @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
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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 Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          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