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. [SOLVED] QTreeView - changing the value of an item in a row when a value in an item on the same row changes
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QTreeView - changing the value of an item in a row when a value in an item on the same row changes

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

    I have a row in my QTreeView which has been created with 4 * QStandardItem (using setChild(row, column, item)).

    The user has clicked on column 3 and edited it. I get that item (using m_model->itemFromIndex(index)). Now I want to update the item in column 1 on the same row. How do I get a pointer to it? All I have is the index of the item in column 3 which was edited.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      AlekseyOk
      wrote on last edited by
      #2

      Hi.
      You have row index ("QModelIndex::row()":http://qt-project.org/doc/qt-4.8/qmodelindex.html#row), so you can get QModelIndex (i.e. model->index(rowIndex, 0)) of desired column

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

        @// obtain the index to the element in the same row in column 1
        QModelIndex target_index = m_model->index(edited_item_index.row(), 1, edited_item_index.parent());
        // change data in the desired item
        m_model->setData(target_index, newdata);@

        I think you get the idea :)

        1 Reply Last reply
        0
        • D Offline
          D Offline
          Dolphin
          wrote on last edited by
          #4

          That works thanks. Happy dance :-)

          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