Results 1 to 17 of 17

Thread: Drag & drop with model/view (Qt4)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Drag & drop with model/view (Qt4)

    What you require is somewhat against traditional approach to drag and drop. What happens if you start a drag (hence remove the item) and then cancel the drag without dropping the item on the widget or if you drop the item on some external application? The drop is traditionally handled by the target and not the source. Of course you can have the behaviour you want by reimplementing mouse events and starting the drag manually (and prior to doing that you need to remove the item from the model) but then you have to handle all possible drop situations manually (and you'll have no information about WHO accepted the drop).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  2. #2
    Join Date
    Jun 2010
    Posts
    15
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Drag & drop with model/view (Qt4)

    Why not traditional? I use chrome browser, when I start drag tab in horizontal direction, it removes from its initial position and sticks to cursor, then I can move it where I want, of course inside tabbar, seems my approach the same.

    Athrough if I move tab outside tab bar, somewhere inside browser window, its like you say, like tab losses it parent. And then if I simply drop tab anywhere, new window will creates for this tab.

    So what I required, if I want during move row, detach it from its initial position?
    Last edited by Nickolay; 19th September 2011 at 19:04.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Drag & drop with model/view (Qt4)

    Quote Originally Posted by Nickolay View Post
    Why not traditional?
    Because typically the operation is performed during the drop and not during the drag.

    I use chrome browser, when I start drag tab in horizontal direction, it removes from its initial position and sticks to cursor, then I can move it where I want, of course inside tabbar, seems my approach the same.
    Your approach is different. For instance you may have multiple views on the same model, removing the item from all the views handling that model is counter-intuitive.

    Athrough if I move tab outside tab bar, somewhere inside browser window, its like you say, like tab losses it parent. And then if I simply drop tab anywhere, new window will creates for this tab.
    That's not the case with your situation, is it? Furthermore look that in Chrome the drop is actually performed during the drag, the tab is not removed when you start dragging it but only when you move it past the border of the next tab (or you drag it outside the tab bar).

    As I said, you can do what you want, but since this is not a typical approach to drag and drop, there is no built-in support for it. You may implement your own view and handle it the way you want.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Jun 2010
    Posts
    15
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Drag & drop with model/view (Qt4)

    Quote Originally Posted by wysota View Post
    That's not the case with your situation, is it? Furthermore look that in Chrome the drop is actually performed during the drag, the tab is not removed when you start dragging it but only when you move it past the border of the next tab (or you drag it outside the tab bar).
    What I need to reimplement in therms of MVC? I need subclass QTableView and override mouse handlers?

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Drag & drop with model/view (Qt4)

    You need to remplement mouse events and rendering-related methods (which in practice makes up most if not all of the view code).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Jun 2010
    Posts
    15
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Drag & drop with model/view (Qt4)

    In very simple case, in current default implementation, to implement row moving inside one table,
    what is the best approach with functions removeRows and insertRows?
    Could I use them directly one after another inside dropMimeData?
    So I can pack in MIME number of line of dragged item and inside dropMimeData I retrieve number of drop line.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Drag & drop with model/view (Qt4)

    Quote Originally Posted by Nickolay View Post
    what is the best approach with functions removeRows and insertRows?
    Could I use them directly one after another inside dropMimeData?
    I would say it is better to use QAbstractItemModel::beginMoveRows() and QAbstractItemModel::endMoveRows() in this case. In a general case dropMimeData() would only insert rows and rows removal would be done in the code when the drag is started when a "move" operation is detected.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Jun 2010
    Posts
    15
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Drag & drop with model/view (Qt4)

    I'm not clearly understand what do you mean.
    generally I didn't get what sense of QAbstractItemModel::beginMoveRows() and QAbstractItemModel::endMoveRows()

    By docs I should use them from removeRows, like

    bool TableModel::removeRows(int position, int rows, const QModelIndex& index)
    {
    Q_UNUSED(index);
    beginRemoveRows(QModelIndex(), position, position + rows - 1);
    endRemoveRows();
    return true;
    }

    But dragging begins from const func mimeData, where I can't call non const method.

    and rows removal would be done in the code when the drag is started when a "move" operation is detected.
    Where that place you have mentioned?
    Last edited by Nickolay; 19th September 2011 at 20:37.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Drag & drop with model/view (Qt4)

    I suggest you read a little about model-view framework in Qt. Everything should become clearer then. One hint -- drag and drop in Qt is handled in the model and not in the view.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 1
    Last Post: 8th January 2009, 17:40
  2. drag and drop QToolButton in QToolBar
    By NBilal in forum Qt Programming
    Replies: 1
    Last Post: 28th December 2008, 20:11
  3. Change cursor & status during Drag & Drop
    By ronlongo in forum Qt Programming
    Replies: 0
    Last Post: 1st December 2008, 16:56
  4. Drag & Drop when parent and childs accept drops?
    By gri in forum Qt Programming
    Replies: 0
    Last Post: 17th October 2008, 09:00
  5. Drag and drop revisited
    By Big Duck in forum Newbie
    Replies: 2
    Last Post: 30th June 2006, 16:41

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.