Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. detect drop event in qt creator
Forum Updated to NodeBB v4.3 + New Features

detect drop event in qt creator

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
7 Posts 3 Posters 2.6k 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.
  • T Offline
    T Offline
    tony67
    wrote on last edited by
    #1

    Hi All,
    I have two qtable views. ui->table_view and ui->table_view2, I have set up to drag and drop from table_view to table_view2. This works OK but always drops to the bottom of table_view2. I've searched everywhere and tried everything to get it to drop over or in between, but it won't.
    So what I thought what I'd do is try to detect when I do a drop event over the table_view2, then find position. However in creator I can't find a slot on the table view that appears to do this.
    Can anyone advise how I find out if an item is dropped over ui->table_view2?

    Thanks

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

      hi
      the drag and drop are functions u can override for a custom class
      http://doc.qt.io/qt-5.5/dnd.html
      being:
      dragEnterEvent -> something being dragged into views area
      dragMoveEvent -> something being dragged inviews area
      dropEvent -> something being dropped into views area

      so dropEvent would be called when u drop the item on say view2

      BUT
      with view, the dropped data is handles by the model
      so if u goal is to insert between 2 other items
      then have a look at
      http://doc.qt.io/qt-5/qabstractitemmodel.html#dropMimeData

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tony67
        wrote on last edited by
        #3

        Hi,
        thank you for the answers, but I'm still slightly puzzled :s.

        Are these functions meant to "override" some low level function, if not how do I tell them to be called? Is something set in the dialog constructor? For example I added them to my table edit dialog, and added a simple qdebug to say I've entered the function, like say I would on a thread or slot, just a test to say "hello world" I'm called. However when I start up my code moving items on the table never calls these?

        
        void Tables_Edit_Dialog::dropMoveEvent(QDropEvent *event)
        {
            qDebug()<<"here";
        }
        
        bool Tables_Edit_Dialog::dropMimeData(int index, const QMimeData *data, Qt::DropAction action)
        {
            qDebug()<<"here 2";
        } 
        
        

        Thankyou

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

          @tony67 said:
          Hi
          they override the default ones.
          They are called by Qt drag&drop system.

          It seems fine for your dialog, but did u remember to
          enable drag & drop for it ?
          else these functions are never called.
          setAcceptDrops(true); in ctor of dialog

          also, im not sure dropMimeData is valid. I have only used that for a model
          NOT a dialog. seems wrong.

          maybe see this
          https://www.youtube.com/watch?v=UlY1J3cfBJI

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tony67
            wrote on last edited by
            #5

            Thanks I'll give the video a watch. I've tried
            [code]
            setAcceptDrops(true);
            [/code]
            and
            [code]
            ui->tableView_2->setAcceptDrops(true);
            [/code]
            in my constructor. But no luck, though I think they must be set as I can drag and drop at the bottom of the list. I'm wondering if it's because I've used designer to set up the tableview drag and drops (I've tried every possible combination ) or if its becuase I'm using Linux. But fear it's just my misunderstanding.

            1 Reply Last reply
            0
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi
              First of all.
              It dont matter if you setup in Designer
              or in code.
              As long as u set it after setup_UI

              Also I think you should really read
              http://doc.qt.io/qt-5/qabstractitemmodel.html#dropMimeData
              and understand its not the view but the model that handles the
              placement of the dropped item.

              i->tableView_2->setAcceptDrops(true);
              Will enable drops to the view. Im not sure what else u expect it to do.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                asanka424
                wrote on last edited by
                #7

                If you want customized drag and drop behavior you have to use a custom data model. Subclass QAbstractItemModel and implement/override the behaviours you want to change. Qt documentation is all what you need.

                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