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. TreeView - Wait until the drop is complete to perform another action
Forum Updated to NodeBB v4.3 + New Features

TreeView - Wait until the drop is complete to perform another action

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 490 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.
  • F Offline
    F Offline
    Flanagan
    wrote on last edited by Flanagan
    #1

    Hello, I have been trying to fix this for more than a week, I do not sleep.

    I am using TreeView with a MyTreeModel (which inherits from QAbstractItemModel). This model is fed by a tree structure with nodes as it appears in the documentation.
    https://doc.qt.io/qt-5/qtwidgets-itemviews-simpletreemodel-example.html
    https://doc.qt.io/qt-5/qtwidgets-itemviews-editabletreemodel-example.html
    https://doc.qt.io/qt-5/model-view-programming.html#using-drag-and-drop-with-item-views

    I have the whole subject of drag and drop between elements of the tree perfectly implemented. As the doc says well, I have reimplemented mimeData, mimeTypes and dropMimeData for it.

    Video of it:
    https://mega.nz/#!bkoTDQSI!YgVn6jIAPJ86fhexzsGySbhrPwQAK5IwlTTeb5L-sQ4

    The problem is that I want to do actions programmatically right after the drop in relation to the item that was dropped.

    I want to expand the item after the drop and I want to select it. The view on the right depends on the currentIndex.

    I have tried everything. Make the selection after:

    • rowsInserted
    • dataChanged
    • currentChanged
    • changeEvent
    • dropEvent
    • eventFilter

    Nothing works because if I try to change the selection after those methods, I break Qt inside causing the not terminated drops not to work well. I need to wait for all the signals derived from the drop to finish to execute the select and expand command.

    I am desperate, I have watched how TreeWidget behaves and has the same problem as me: when the drop is made the row selected is wrong and the node collapsed.

    What I can do?

    Thank you very much.

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2
      1. I'm not sure why anything should break. Run your model throught the model test to make sure it's implemented 100% according to Qt's expectation
      2. adding Qt::QueuedConnection as the 5th argument of your connect ststement should ensure your code gets executed after the move is completed and control is given back to Qt's event loop

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      F 1 Reply Last reply
      3
      • VRoninV VRonin
        1. I'm not sure why anything should break. Run your model throught the model test to make sure it's implemented 100% according to Qt's expectation
        2. adding Qt::QueuedConnection as the 5th argument of your connect ststement should ensure your code gets executed after the move is completed and control is given back to Qt's event loop
        F Offline
        F Offline
        Flanagan
        wrote on last edited by Flanagan
        #3

        @VRonin You are a god. Finally I have finished the implementation thanks to your second option. I have tried (all possible combinations) and it works.
        I didn't know about Qt::QueuedConnection and the option to concatenate signals to the Qt event queue. This is going to be very useful to me.

        You have saved me and it is not the first time, I have seen your answers in other threads and they have helped me too.

        Thanks from Spain and sorry if my English is bad.

        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