Qt Forum

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

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

    General and Desktop
    2
    4
    800
    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.
    • O
      opengpu2 last edited by

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

      1 Reply Last reply Reply Quote 0
      • S
        Sam last edited by Sam

        @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 Reply Quote 0
        • O
          opengpu2 last edited by opengpu2

          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 Reply Quote 0
          • S
            Sam last edited by

            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 Reply Quote 0
            • First post
              Last post