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. Set a text of cell in QTreeWidget
Forum Updated to NodeBB v4.3 + New Features

Set a text of cell in QTreeWidget

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

    Hello, please how is possible to set a text in QTreeWidget? For example I would like to set a text "hello" at index [3,2] (row,column).

    Like on this picture below, instead of "10" set text "hello":

    image

    Thank you

    Student who loves C/C++

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chrisw01
      wrote on last edited by
      #2

      Hi,

      have you tried setText() of the item?

      1 Reply Last reply
      0
      • T Offline
        T Offline
        t0msk
        wrote on last edited by
        #3

        How?

        function

        ui->treeWidget->setText();
        

        doesn't exist

        Student who loves C/C++

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

          Hi,

          @Chrisw01 meant QTreeWidgetItem::setText.

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

          T 1 Reply Last reply
          0
          • SGaistS SGaist

            Hi,

            @Chrisw01 meant QTreeWidgetItem::setText.

            T Offline
            T Offline
            t0msk
            wrote on last edited by t0msk
            #5

            @SGaist said in Set a text of cell in QTreeWidget:

            Hi,

            @Chrisw01 meant QTreeWidgetItem::setText.

            Thanks so it pass a column number and text, but how can I tell which row? I need to get QTreeWidgetItem from QTreeWidget somehow.

            Student who loves C/C++

            1 Reply Last reply
            0
            • C Offline
              C Offline
              Chrisw01
              wrote on last edited by Chrisw01
              #6

              IIRC each row is a topLevelItem with children under them so in this case Hello is the topLevelItem and branches on from there.

              So Day would be the child of nice which is a child of hello.

              QTreeWidgetItem *item = ui->treeWidget->topLevelItem(row)->child(row)->child(row); // in this case row = 0
              
              item->setText(col, "TEXT");  // where in this case  col would be 1
              

              or something along those lines.

              1 Reply Last reply
              1
              • T Offline
                T Offline
                t0msk
                wrote on last edited by
                #7

                Ah now, I understand.

                Thank you very much :)

                Student who loves C/C++

                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