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 into empty widget space
QtWS25 Last Chance

Drag and Drop into empty widget space

Scheduled Pinned Locked Moved Solved General and Desktop
drag and dropqwidgetdropdrag
5 Posts 2 Posters 2.6k Views
  • 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
    Vagabond
    wrote on 7 Jun 2016, 14:58 last edited by
    #1

    I would like to know whether or not it is possible to drag and drop into (what I want to refer to as) empty widget space.

    To be more precise:

    I have defined a MultiTrackPlayer class derived from QWidget. This Player dynamically adds a PlayerControls (play button/pause button/...) for each track added to it. At this point adding new PlayerControls is triggered by button press and then delivering a QUrl, which references the media file to be played, to the MultiTrackPlayer. I would like to replace the button click, by dragging Urls into the yet to be filled layout space of my MultiTrackMediaPlayer.

    I successfully implemented drag and drop on my custom QListView, overriding

    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    void dragEnterEvent(QDragEnterEvent *event);
    void dragMoveEvent(QDragMoveEvent *event);
    void dropEvent(QDropEvent *event);
    

    and setting

    setAcceptDrops(true);
    

    Using the same procedure on MultiTrackPlayer does not give me any ability to perform the above described behaviour. I am assuming that is because the empty layout space is not treated as a legal drop site!?

    How would I handle this correctly, can anyone point me into the right direction?

    Thanks! =)

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 7 Jun 2016, 15:09 last edited by
      #2

      hi
      can u show the empty widget space?

      V 1 Reply Last reply 8 Jun 2016, 11:55
      0
      • M mrjj
        7 Jun 2016, 15:09

        hi
        can u show the empty widget space?

        V Offline
        V Offline
        Vagabond
        wrote on 8 Jun 2016, 11:55 last edited by
        #3

        @mrjj
        The empty space you see in the attached image is basically the layout which all PlayerControls are added to, held by a QGroupBox titled "Players:".
        That being said, do I have to configure my drag and drop functionality on the QGroupBox rather then the MultiTrackPlayer?

        1 Reply Last reply
        0
        • V Offline
          V Offline
          Vagabond
          wrote on 8 Jun 2016, 12:22 last edited by Vagabond 6 Aug 2016, 12:23
          #4

          Okay I added a class derived from QGroupBox to host my drop events

          void dragEnterEvent(QDragEnterEvent *event);
          void dragMoveEvent(QDragMoveEvent *event);
          void dropEvent(QDropEvent *event);
          

          using this groupbox to hold the MultiTrackPlayer layout gives me the functionality I was looking for. Thanks @mrjj for the comment. Replying to it inspired me to try that out.

          =)

          M 1 Reply Last reply 8 Jun 2016, 12:31
          2
          • V Vagabond
            8 Jun 2016, 12:22

            Okay I added a class derived from QGroupBox to host my drop events

            void dragEnterEvent(QDragEnterEvent *event);
            void dragMoveEvent(QDragMoveEvent *event);
            void dropEvent(QDropEvent *event);
            

            using this groupbox to hold the MultiTrackPlayer layout gives me the functionality I was looking for. Thanks @mrjj for the comment. Replying to it inspired me to try that out.

            =)

            M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 8 Jun 2016, 12:31 last edited by
            #5

            @Vagabond
            Heh. good work.

            Just as a note:
            you can use event filters to implement drag and drop on other widgets if
            no other need to subclass them.

            http://ynonperek.com/course/qt/event-filter2.html

            But for your case, subclassing QGroupBox is super.

            1 Reply Last reply
            1

            3/5

            8 Jun 2016, 11:55

            • Login

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