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. how can i get the QTreeWidgetItem in its delegate's setModelData() func??

how can i get the QTreeWidgetItem in its delegate's setModelData() func??

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 955 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.
  • O Offline
    O Offline
    opengpu2
    wrote on last edited by
    #1

    how can i get the QTreeWidgetItem in its delegate's setModelData() func??

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Sam
      wrote on last edited by Sam
      #2

      @opengpu2

      Normally in the delegate class we use the model() (QAbstractItemModel) which is provided in the functions that we override. However what you set to the model()->setData() it will automatically update the item (based on the roles : DisplayRole, UserRole etc). In order to access the data you can use model->data(index,Qt::DisplayRole).toString();

      1 Reply Last reply
      0
      • O Offline
        O Offline
        opengpu2
        wrote on last edited by opengpu2
        #3

        thank you , got it.
        so how should i got the parentWidgetItem of the currentItem?

        QModelIndex parentIndex = model->parent(index);
        or
        QModelIndex parentIndex = index.parent();

        or they are same?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Sam
          wrote on last edited by
          #4

          Both are the same for more details you can check the documentation QAbstractItemModel::parent(const QModelIndex & index) and QModelIndex::parent()

          make sure that you check if the index isValid() then only proceed with next operation.

          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