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. Drag and drop text displayed between QGLWidget
Forum Updated to NodeBB v4.3 + New Features

Drag and drop text displayed between QGLWidget

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 3 Posters 2.2k Views 3 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.
  • Q Offline
    Q Offline
    QtVik
    wrote on 6 Feb 2018, 10:28 last edited by QtVik 2 Jun 2018, 12:32
    #1

    How to drag and drop text displayed in one QGLWidget to another QGLWidget within a QT application?

    I have re-implemented the methods dragMoveEvent, dropEvent, dragEnterEvent, dragLeaveEvent

    and included setAcceptDrops(true) in the constructor also.

    But still breakpoint is not hit in any of the above overridden methods even if i drag and drop between widgets.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 6 Feb 2018, 21:24 last edited by
      #2

      Hi,

      Can you show the code you are using ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • Q Offline
        Q Offline
        QtVik
        wrote on 7 Feb 2018, 05:52 last edited by
        #3

        @SGaist :
        Following is the code:

        class MyView: public QGLWidget, public baseWidget
        {
        public:
        MyView::MyView()
        {
        setAcceptDrops(true);
        }
        protected:
        dragMoveEvent(QDragMoveEvent* event)
        {
        event->accept();
        }
        dragEnterEvent(QDragEnterEvent* event)
        {
        event->acceptProposedAction();
        }
        dragLeaveEvent(QDragLeaveEvent* event)
        {
        }
        dropEvent(QDropEvent* event)
        {
        }
        };

        I am creating the views through mainWindow class derived from QMainWindow.
        Please advice me how to write a dragEvent() while dragging within two different views.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 7 Feb 2018, 07:25 last edited by
          #4

          These are empty methods, you won't get custom drag and drop behaviour with just that.

          Did you read the dedicated chapter about it in Qt's documentation ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          Q 1 Reply Last reply 7 Feb 2018, 08:15
          1
          • S SGaist
            7 Feb 2018, 07:25

            These are empty methods, you won't get custom drag and drop behaviour with just that.

            Did you read the dedicated chapter about it in Qt's documentation ?

            Q Offline
            Q Offline
            QtVik
            wrote on 7 Feb 2018, 08:15 last edited by
            #5

            @SGaist Thank you.
            Will go through that and try..

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 7 Feb 2018, 09:41 last edited by
              #6

              Hi
              The
              http://doc.qt.io/qt-5/qtwidgets-draganddrop-draggabletext-example.html
              is pretty close to what you want.

              Q 1 Reply Last reply 7 Feb 2018, 11:25
              1
              • M mrjj
                7 Feb 2018, 09:41

                Hi
                The
                http://doc.qt.io/qt-5/qtwidgets-draganddrop-draggabletext-example.html
                is pretty close to what you want.

                Q Offline
                Q Offline
                QtVik
                wrote on 7 Feb 2018, 11:25 last edited by
                #7

                @mrjj Thank you.
                Will try it and update.

                1 Reply Last reply
                0
                • Q Offline
                  Q Offline
                  QtVik
                  wrote on 13 Feb 2018, 03:50 last edited by
                  #8

                  @SGaist @mrjj :

                  I was trying to use Q_DECLARE_METATYPE in drag object to copy the data from one widget to another.
                  The meta type is declared something like below:
                  Class MyView : public QGLWidget, public BaseWidget
                  {
                  public:
                  struct my_struct{
                  int m_var;
                  };
                  Q_DECLARE_METATYPE(my_struct)
                  };
                  But I am getting following errors:
                  error: explicit specialization in non-namespace scope ‘class MyView’
                  error: expected primary-expression before ‘>’ token reinterpret_cast< TYPE *>(quintptr(-1)));
                  error: expected ‘(’ before ‘my_struct’ Q_DECLARE_METATYPE(my_struct)

                  What is right way of declaring a Q_DECLARE_METATYPE ?

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 13 Feb 2018, 07:13 last edited by
                    #9

                    Hi

                    I think it likes better if classes are not nested.

                    struct my_struct{
                    int m_var;
                    };
                    Q_DECLARE_METATYPE(my_struct)

                    Class MyView : public QGLWidget, public BaseWidget
                    {
                    public:
                    my_struct myvar;
                    };

                    1 Reply Last reply
                    1
                    • Q Offline
                      Q Offline
                      QtVik
                      wrote on 13 Feb 2018, 07:22 last edited by QtVik
                      #10

                      @mrjj : Thank you! you are absolutely right :)

                      One more query is how to handle mouse events when drag object is used ?
                      drag object seems to block all the mouse events.

                      I have created a drag object inside mousePressEvent() . Wanted to copy the string list from one widget to another.
                      I wanted to handle dropping of QList in mouseReleaseEvent() but as soon as drag object is created it blocks all mouse events.

                      M 1 Reply Last reply 13 Feb 2018, 07:29
                      0
                      • Q QtVik
                        13 Feb 2018, 07:22

                        @mrjj : Thank you! you are absolutely right :)

                        One more query is how to handle mouse events when drag object is used ?
                        drag object seems to block all the mouse events.

                        I have created a drag object inside mousePressEvent() . Wanted to copy the string list from one widget to another.
                        I wanted to handle dropping of QList in mouseReleaseEvent() but as soon as drag object is created it blocks all mouse events.

                        M Offline
                        M Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on 13 Feb 2018, 07:29 last edited by mrjj
                        #11

                        @QtVik
                        Super.

                        Regarding drag & drop.
                        You should fully use the drag system to do so.
                        http://doc.qt.io/qt-5/dnd.html
                        http://doc.qt.io/qt-5/qdropevent.html

                        Here it drops pictures.
                        http://doc.qt.io/qt-5/qtwidgets-draganddrop-puzzle-example.html
                        you can drop anything u like this way.

                        Q 1 Reply Last reply 13 Feb 2018, 08:38
                        1
                        • M mrjj
                          13 Feb 2018, 07:29

                          @QtVik
                          Super.

                          Regarding drag & drop.
                          You should fully use the drag system to do so.
                          http://doc.qt.io/qt-5/dnd.html
                          http://doc.qt.io/qt-5/qdropevent.html

                          Here it drops pictures.
                          http://doc.qt.io/qt-5/qtwidgets-draganddrop-puzzle-example.html
                          you can drop anything u like this way.

                          Q Offline
                          Q Offline
                          QtVik
                          wrote on 13 Feb 2018, 08:38 last edited by
                          #12

                          @mrjj Thank you ! will try that and update..

                          1 Reply Last reply
                          0
                          • Q Offline
                            Q Offline
                            QtVik
                            wrote on 19 Feb 2018, 10:45 last edited by
                            #13

                            Hi @mrjj @SGaist : Thank you for the inputs. It worked !

                            1 Reply Last reply
                            1

                            1/13

                            6 Feb 2018, 10:28

                            • Login

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