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. DropMimeData is not getting called for extended QTableWidget
Qt 6.11 is out! See what's new in the release blog

DropMimeData is not getting called for extended QTableWidget

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 5.0k 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.
  • V Offline
    V Offline
    vikas2all
    wrote on last edited by
    #1

    I have extended QTableWidget to create a custom tableWidget. I want to override the dropMimeData method. But dropMimeData() is not getting called.

    Here is my code.

    mytablewidget1.h
    @
    #include <QtGui>

    class myTableWidget1 : public QTableWidget
    {
    Q_OBJECT
    public:

    myTableWidget1(QWidget *parent = 0);
    
    virtual bool dropMimeData(int row, int column, const QMimeData *data, Qt::DropAction action);
    QStringList mimeTypes() const;
    Qt::DropActions supportedDropActions () const;
    

    };@

    mytablewidget.cpp

    @
    #include "mytablewidget1.h"
    #include <iostream>

    myTableWidget1::myTableWidget1(QWidget *parent) :
    QTableWidget(3,3,parent)
    {
    this->dragEnabled();
    setSelectionMode(QAbstractItemView::SingleSelection);
    setDragDropMode(QAbstractItemView::InternalMove);

    QTableWidgetItem *item=new QTableWidgetItem();
    item->setText("1,1");
    setItem(1,1,item);
    
    item=new QTableWidgetItem();
    item->setText("2,2");
    setItem(2,2,item);
    

    }

    bool myTableWidget1::dropMimeData(int row, int column, const QMimeData *data, Qt::DropAction action)
    {
    std::cout<<"in dropMineData......."<<std::endl;

        return true;
    

    }

    QStringList myTableWidget1::mimeTypes () const
    {

        QStringList qstrList;
    
        qstrList.append("text/uri-list");
        return qstrList;
    

    }

    Qt::DropActions myTableWidget1::supportedDropActions () const
    {
    return Qt::CopyAction | Qt::MoveAction;
    }@


    main.cpp

    @
    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);
    myTableWidget1 *dialog = new myTableWidget1(5,5);

    dialog->show();
    return app.exec(&#41;;
    

    }@

    [Edit: please use @ code tags for code, Eddy]

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      You did not set the drag/drop on the viewport. From the "docs:":http://doc.qt.nokia.com/4.7/model-view-programming.html#using-drag-and-drop-with-item-views

      @
      QListWidget *listWidget = new QListWidget(this);
      listWidget->setSelectionMode(QAbstractItemView::SingleSelection);
      listWidget->setDragEnabled(true);
      listWidget->viewport()->setAcceptDrops(true);
      listWidget->setDropIndicatorShown(true);
      @

      The method you use (dragEnabled) does not enable it, it is a getter.

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vikas2all
        wrote on last edited by
        #3

        Setting DragDropMode to QAbstractItemView::DragDrop worked for me. Earlier i was using setDragDropMode(QAbstractItemView::InternalMove).

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved