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. Qt47::Drag&Drop events using eventFilter
Forum Updated to NodeBB v4.3 + New Features

Qt47::Drag&Drop events using eventFilter

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

    Hello,

    using QListView I installed a filter which is printing all events' received for the QListView object.
    The

    setDragEnabled(true)
    setAcceptDrops(true)

    were executed on the QListView object.

    At first there were DragEnter (60) events received. But after several app. executions there were no drag&drop events received.

    Is this a bug in QT 4.7?

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      can you post some related code please.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • S Offline
        S Offline
        silex92
        wrote on last edited by
        #3

        Between, I'd started the app. again and the event 60 was caught! It works time to time.

        The methods are called in a constructor of the event_dlg object.
        @void event_dlg::tune_listview()
        {
        events_listview_raw_ptr->setModel(events_list_model_raw_ptr);
        events_listview_raw_ptr->setFixedWidth(events_listview_width);
        events_listview_raw_ptr->setSelectionMode(QAbstractItemView::SelectionMode::SingleSelection);
        events_listview_raw_ptr->setDragEnabled(true);
        events_listview_raw_ptr->setAcceptDrops(true);
        events_listview_raw_ptr->setDropIndicatorShown(true);
        }@
        @events_listview_raw_ptr->installEventFilter(this);@

        @event_dlg::~event_dlg()
        {
        events_listview_raw_ptr->removeEventFilter(this);
        }@
        @bool event_dlg::eventFilter(QObject *watched_raw_ptr, QEvent *event_raw_ptr)
        {
        if ( watched_raw_ptr != nullptr && event_raw_ptr != nullptr)
        if ( watched_raw_ptr == events_listview_raw_ptr )
        {
        qDebug() << "listview raw pointer is filtered => " << event_raw_ptr->type();
        //synchronize_view_and_model();
        return false;
        }
        return QDialog::eventFilter( watched_raw_ptr, event_raw_ptr );
        }@

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Sam
          wrote on last edited by
          #4

          -Kindly use @ tags for code formatting which makes it easy for others to understand . Its at the extreme right corner of the Reply Box.-

          Already done :)

          1 Reply Last reply
          0
          • raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #5

            you are only checking the listview itself. But the events get sent to it's viewport instead (which propagate them to the listview itself if not processed).
            So install an eventfilter on the viewport of the listview and you will see the "missing" events.

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0
            • S Offline
              S Offline
              silex92
              wrote on last edited by
              #6

              Yes. What is the difference between the viewport and the widget itself?
              [quote author="raven-worx" date="1379404414"]you are only checking the listview itself. But the events get sent to it's viewport instead (which propagate them to the listview itself if not processed).
              So install an eventfilter on the viewport of the listview and you will see the "missing" events.[/quote]

              1 Reply Last reply
              0
              • S Offline
                S Offline
                Sam
                wrote on last edited by
                #7

                This might help a bit : "What’s relationship between viewport(), widget() and QScrollArea":http://qt-project.org/forums/viewthread/3427

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  silex92
                  wrote on last edited by
                  #8

                  How to receive any drag related event before the mimeData is called?

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    Sam
                    wrote on last edited by
                    #9

                    One solution is to create your own custom listView and override some of the methods like

                    @void dragEnterEvent(QDragEnterEvent *event);
                    void dragMoveEvent(QDragMoveEvent *event);
                    void dropEvent(QDropEvent *event);
                    void startDrag(Qt::DropActions supportedActions);
                    void mousePressEvent(QMouseEvent *event);
                    void mouseMoveEvent(QMouseEvent *event);@

                    You can also check the following examples

                    1. "Draggable Icons Example":http://qt-project.org/doc/qt-4.8/draganddrop-draggableicons.html
                    2. "Drag and Drop Puzzle Example":http://qt-project.org/doc/qt-4.8/draganddrop-puzzle.html
                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      silex92
                      wrote on last edited by
                      #10

                      dragEnterEvent is the default action for the QEvent::DragEnter in the QListView type if I am not mistaken.
                      Probably the startDrag should be the right choice. The "QAbstractItemView documentation":http://harmattan-dev.nokia.com/docs/library/html/qt4/qabstractitemview.html?tab=3&q=QListView#startDrag
                      does not provide such information.

                      1 Reply Last reply
                      0
                      • raven-worxR Offline
                        raven-worxR Offline
                        raven-worx
                        Moderators
                        wrote on last edited by
                        #11

                        [quote author="Sam" date="1379412553"]One solution is to create your own custom listView and override some of the methods like

                        @void dragEnterEvent(QDragEnterEvent *event);
                        void dragMoveEvent(QDragMoveEvent *event);
                        void dropEvent(QDropEvent *event);
                        void startDrag(Qt::DropActions supportedActions);
                        void mousePressEvent(QMouseEvent *event);
                        void mouseMoveEvent(QMouseEvent *event);@
                        [/quote]

                        Better override QAbstractItemView::viewportEvent() or it will result in the initial problem.

                        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                        If you have a question please use the forum so others can benefit from the solution in the future

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          silex92
                          wrote on last edited by
                          #12

                          Could you explain why (in details)?
                          [quote author="raven-worx" date="1379413191"][quote author="Sam" date="1379412553"]One solution is to create your own custom listView and override some of the methods like

                          @void dragEnterEvent(QDragEnterEvent *event);
                          void dragMoveEvent(QDragMoveEvent *event);
                          void dropEvent(QDropEvent *event);
                          void startDrag(Qt::DropActions supportedActions);
                          void mousePressEvent(QMouseEvent *event);
                          void mouseMoveEvent(QMouseEvent *event);@
                          [/quote]

                          Better override QAbstractItemView::viewportEvent() or it will result in the initial problem.

                          [/quote]

                          1 Reply Last reply
                          0
                          • raven-worxR Offline
                            raven-worxR Offline
                            raven-worx
                            Moderators
                            wrote on last edited by
                            #13

                            [quote author="silex92" date="1379413278"]Could you explain why (in details)?
                            [/quote]
                            When you look into the Qt source code you will see that viewportEvent() is actually the same like we already came up in the posts before (eventfilter on the viewport). When subclassing use this method instead of an eventfilter.

                            [quote author="silex92" date="1379413166"]dragEnterEvent is the default action for the QEvent::DragEnter in the QListView type if I am not mistaken.
                            Probably the startDrag should be the right choice. The "QAbstractItemView documentation":http://harmattan-dev.nokia.com/docs/library/html/qt4/qabstractitemview.html?tab=3&q=QListView#startDrag
                            does not provide such information.[/quote]

                            What exactly do you want to achieve actually?

                            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                            If you have a question please use the forum so others can benefit from the solution in the future

                            1 Reply Last reply
                            0
                            • S Offline
                              S Offline
                              silex92
                              wrote on last edited by
                              #14

                              There's a QListView and additional view - QStackedWidget which provides the actual information for each QListView object.
                              Hence, the pages(QStackedWidget) should be synchronized manually.
                              When the pages' information is input by an user, the model is not updated. Hence, before the mimeData method is invoked the model should be updated.
                              [quote author="raven-worx" date="1379413166"]
                              What exactly do you want to achieve actually?
                              [/quote]

                              1 Reply Last reply
                              0
                              • raven-worxR Offline
                                raven-worxR Offline
                                raven-worx
                                Moderators
                                wrote on last edited by
                                #15

                                so you just need to update the model as soon as something changes in your "pages" right?

                                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                                If you have a question please use the forum so others can benefit from the solution in the future

                                1 Reply Last reply
                                0
                                • S Offline
                                  S Offline
                                  silex92
                                  wrote on last edited by
                                  #16

                                  The model should be updated only if an event is dragged.
                                  [quote author="raven-worx" date="1379414696"]so you just need to update the model as soon as something changes in your "pages" right?[/quote]

                                  1 Reply Last reply
                                  0
                                  • raven-worxR Offline
                                    raven-worxR Offline
                                    raven-worx
                                    Moderators
                                    wrote on last edited by
                                    #17

                                    [quote author="silex92" date="1379414823"]The model should be updated only if an event is dragged.
                                    [/quote]

                                    Then listen for the drag-enter event.

                                    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                                    If you have a question please use the forum so others can benefit from the solution in the future

                                    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