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. Using QTreeWidget drag & drop with QDomDocument
Forum Updated to NodeBB v4.3 + New Features

Using QTreeWidget drag & drop with QDomDocument

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.7k 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
    dst2
    wrote on last edited by
    #1

    Hi everyone,

    In my application, I have a QTreeWidget that allows the user to reorganize the ordering of its items by dragging and dropping them. I also have a QDomDocument that represents the structure of the QTreeWidget, so when the user moves an item, I want the position of the nodes in the QDomDocument to be updated to reflect this new arrangement. The nodes are uniquely identified by their attributes.

    What functions do I need to use or reimplement to accomplish this? I found the QDomNode::insertBefore() and insertAfter() functions, so it seems like I just need to remove the node from its original position and then call insertBefore() or insertAfter() to put it in its new position. I think I need to reimplement QTreeWidget::dropEvent, and then do the QDom updating in there. But how can I detect the original position and the new position of the node inside dropEvent?

    Thanks for any help you can give.

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      first you need to make sure that the drag contains the data you need to identify the domnode. This can be some custom mime type. This can be done by implementing a custom model and reimplement "QAbstractItemModel::dropMimeData()":http://qt-project.org/doc/qt-4.8/qabstractitemmodel.html#dropMimeData

      Then you can reimplement "QTreeWidget::dropMimeData()":http://qt-project.org/doc/qt-4.8/qtreewidget.html#dropMimeData and read your custom mime data there.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dst2
        wrote on last edited by
        #3

        Hi,

        I'm sorry, I don't quite understand what you are suggesting. Do you propose replacing my QTreeWidget with a reimplementation of QAbstractItemModel in order to have a copy of the item's title inside dropMimeData()? I was planning on simply using QTreeWidget::selectedItems() inside dropEvent() and thereby obtaining the title of the dragged item, which I can use to find the corresponding node in the QDomDocument. My QTreeWidget only allows selection of one item at a time so there is no ambiguity.

        Also, I still don't know how I can detect the new position of the QTreeWidgetItem once it is dropped, which is the real heart of my question.

        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