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] Dragging from a QTableView to a QTreeView - order of events
QtWS25 Last Chance

[Solved] Dragging from a QTableView to a QTreeView - order of events

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

    I'm trying to drag from a QTableView to a QTreeView. My QTableView is called "partsview" and is descended from a QTableView. The relevant bits of the header are:

    @class partsiew : public QTableView
    {
    Q_OBJECT
    public:
    explicit partsview(QWidget *parent = 0);
    public:
    QStringList mimeTypes() const;
    QMimeData *mimeData(const QModelIndexList &indexes) const;
    };
    @

    I have also added the following into the constructor of "partsview":

    @this->setSelectionMode(QAbstractItemView::ExtendedSelection);
    this->setDragEnabled(true);@

    When I attempt to drag an item the cursor changes appropriately, I can drop onto the QTreeView and I get a dropMimeData event is fired on the treeview.

    What I'm finding is that the two methods mimeTypes() and mimeData() are not called and the row and column values in the dropMimeData() event are both -1.

    So:
    o What order are the events/methods called? Should I get a call to mimeData() before I get a dropMimeData() event? (I'm wodering if this call only happens when a successful drop occurs).

    o Have I declared the mimeTypes() and mimeData() events/methods correctly so that they will be called at appropriate times?

    Any other pointers appreciated.

    Thank you,

    Mike

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Because these two methods don't belong to QTableView. You can find them in the QTable/List/TreeWidget classes but they are a special case. With the View version of the classes, you need to implement them in your model. That will also allow you to change the view and still be able to do drag and drop without having to subclass the views.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MichaelVincent
        wrote on last edited by
        #3

        Ahhh! Gotcha.

        Thank you.

        Mike

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You're welcome !

          Since you have your model working now, please update the thread title prepending [solved] so other forum users my know a solution has been found :)

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          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