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. Drop Event without Subclass
Qt 6.11 is out! See what's new in the release blog

Drop Event without Subclass

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 862 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.
  • D Offline
    D Offline
    deleted122
    wrote on last edited by
    #1

    Hi guys,

    i am creating a desktop application and i am struggling with QDropEvent.
    I have a QDialog in my application containing 2 QListViews.
    One list view is filled with a String List.
    The task is to choose text from this first ListView and Drag it into the second one.
    This is working fine.
    But i want to have an event fired everytime some String is dropped into the second ListView.

    The solution that i know about is to subclass QListView and create a dropEvent there.
    What i want to do is to not have to subclass QListView, i found out it is possible to catch events by using the Event filter and checking the event that happened.
    Problem is: i never get a Drop event

    Here the relevant code:
    myClass.h

    class test : public QDialog
    {
    Q_OBJECT
    ...
    protected:
    bool eventFilter(QObject *watched, QEvent *event);
    
    ...
    

    myClass.c

    test:test()
    {
    QListView *left = new QListView(this);
    left->setAcceptDrops(false);
    left->setDragEnabled(true);
    left->setDropIndicatorShown(true);
    left->setEditTriggers(QAbstractItemView::NoEditTriggers);
    left->setModel(model);
    left->installEventFilter(this);
    
    //same for the second one, just AcceptDrops = true and DragEnabled = false
    
    }
    
    bool test:eventFilter(QObject *watched, QEvent *event)
    {
    if(event->type() == QEvent::Drop)
    {
    qDebug()<<"Say hello from Drop";
    return true;
    }
    else
    {
    retrun QObject::eventFilter(watched,event);
    }
    

    Any Ideas how to fix this or how to make it work without using the event filter are welcome
    Thanks guys!

    P.S: if you need more information just ask i will provide more if needed

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Please take a look at the drag and drop documentation here: http://doc.qt.io/qt-5/dnd.html

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

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

        Hi
        Please be advised that the Views have a viewport object
        and in most cases the events goes to it and not the
        actual *View class. So you might need eventfilter on that instead.

        its accessible via ui->ViewX->viewport()

        1 Reply Last reply
        2

        • Login

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