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
Forum Updated to NodeBB v4.3 + New Features

Drag and Drop into empty widget space

Scheduled Pinned Locked Moved Solved General and Desktop
drag and dropqwidgetdropdrag
5 Posts 2 Posters 2.7k Views 2 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.
  • VagabondV Offline
    VagabondV Offline
    Vagabond
    wrote on 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
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      hi
      can u show the empty widget space?

      VagabondV 1 Reply Last reply
      0
      • mrjjM mrjj

        hi
        can u show the empty widget space?

        VagabondV Offline
        VagabondV Offline
        Vagabond
        wrote on 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
        • VagabondV Offline
          VagabondV Offline
          Vagabond
          wrote on last edited by Vagabond
          #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.

          =)

          mrjjM 1 Reply Last reply
          2
          • VagabondV Vagabond

            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.

            =)

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on 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

            • Login

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