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. Trying to implement a drop function on a QFrame, help please!
Forum Updated to NodeBB v4.3 + New Features

Trying to implement a drop function on a QFrame, help please!

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

    In the mainwindow.ui file, the Qframe that I need to enable the drop function is organized as follows:

    MainWindow(QMainWindow) -> centralwidget(QWidget) -> stackedWidget(QStackedWidget) -> page3(QWidget) -> frame_12(QFrame) -> frame_17(Qframe).

    The last one, frame_17, is the frame where i need to drop zip files. Trying to figure out in internet how to do it, I did this:

    /_____________________________________________
    dropimages.h

    #ifndef DROPIMAGES_H
    #define DROPIMAGES_H
    
    #include <QWidget>
    #include <QFrame>
    
    class DropImages : public QFrame
    {
    
    public:
        explicit DropImages(QWidget *parent = nullptr);
    
    protected:
        void dragEnterEvent(QDragEnterEvent *event) override;
    
        void dragMoveEvent(QDragMoveEvent *event) override;
    
        void dropEvent(QDropEvent *event) override;
    };
    
    #endif // DROPIMAGES_H
    

    /_____________________________________________

    dropimages.cpp

    #include "dropimages.h"
    
    #include <QDrag>
    #include <QDragEnterEvent>
    #include <QMimeData>
    
    DropImages::DropImages(QWidget *parent)
        : QFrame(parent)
    {
        setAcceptDrops(true);
    }
    
    void DropImages::dragEnterEvent(QDragEnterEvent *event)
    {
        printf("cccccc\n"); // for test
        event->accept();
        if(event->mimeData()->hasUrls())
            event->acceptProposedAction();
    }
    
    void DropImages::dragMoveEvent(QDragMoveEvent *event)
    {
        printf("bbbb\n"); // for test
        event->accept();
        if(event->mimeData()->hasUrls())
        {
            event->acceptProposedAction();
        }
    }
    
    void DropImages::dropEvent(QDropEvent *event)
    {
        printf("aaaaaa\n"); // for test
        event->accept();
        if(event->mimeData()->hasUrls())
        {
            foreach(QUrl url, event->mimeData()->urls())
            {
                printf(url.toLocalFile().toStdString().c_str());
            }
        }
    }
    

    /_____________________________________________

    mainwindow.cpp

    inside class implementation:
    DropImages *uploadedImages = new DropImages(ui->frame_17);

    /_____________________________________________

    But nothing is working. Can someone help me please?

    JonBJ Pl45m4P 2 Replies Last reply
    0
    • fabriciokashF fabriciokash

      In the mainwindow.ui file, the Qframe that I need to enable the drop function is organized as follows:

      MainWindow(QMainWindow) -> centralwidget(QWidget) -> stackedWidget(QStackedWidget) -> page3(QWidget) -> frame_12(QFrame) -> frame_17(Qframe).

      The last one, frame_17, is the frame where i need to drop zip files. Trying to figure out in internet how to do it, I did this:

      /_____________________________________________
      dropimages.h

      #ifndef DROPIMAGES_H
      #define DROPIMAGES_H
      
      #include <QWidget>
      #include <QFrame>
      
      class DropImages : public QFrame
      {
      
      public:
          explicit DropImages(QWidget *parent = nullptr);
      
      protected:
          void dragEnterEvent(QDragEnterEvent *event) override;
      
          void dragMoveEvent(QDragMoveEvent *event) override;
      
          void dropEvent(QDropEvent *event) override;
      };
      
      #endif // DROPIMAGES_H
      

      /_____________________________________________

      dropimages.cpp

      #include "dropimages.h"
      
      #include <QDrag>
      #include <QDragEnterEvent>
      #include <QMimeData>
      
      DropImages::DropImages(QWidget *parent)
          : QFrame(parent)
      {
          setAcceptDrops(true);
      }
      
      void DropImages::dragEnterEvent(QDragEnterEvent *event)
      {
          printf("cccccc\n"); // for test
          event->accept();
          if(event->mimeData()->hasUrls())
              event->acceptProposedAction();
      }
      
      void DropImages::dragMoveEvent(QDragMoveEvent *event)
      {
          printf("bbbb\n"); // for test
          event->accept();
          if(event->mimeData()->hasUrls())
          {
              event->acceptProposedAction();
          }
      }
      
      void DropImages::dropEvent(QDropEvent *event)
      {
          printf("aaaaaa\n"); // for test
          event->accept();
          if(event->mimeData()->hasUrls())
          {
              foreach(QUrl url, event->mimeData()->urls())
              {
                  printf(url.toLocalFile().toStdString().c_str());
              }
          }
      }
      

      /_____________________________________________

      mainwindow.cpp

      inside class implementation:
      DropImages *uploadedImages = new DropImages(ui->frame_17);

      /_____________________________________________

      But nothing is working. Can someone help me please?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @fabriciokash said in Trying to implement a drop function on a QFrame, help please!:

      But nothing is working

      Do you mean none of these methods are hit?

      MainWindow(QMainWindow) -> centralwidget(QWidget) -> stackedWidget(QStackedWidget) -> page3(QWidget) -> frame_12(QFrame) -> frame_17(Qframe).

      You say frame_12 is a QFrame (perhaps created in Designer?). But your class is DropImages, derived from QFrame. So this would be a third frame level? May I suggest you start by, say, setting the background color of your DropImages to red so that you can at least it is there and what area it covers?

      fabriciokashF 1 Reply Last reply
      1
      • JonBJ JonB

        @fabriciokash said in Trying to implement a drop function on a QFrame, help please!:

        But nothing is working

        Do you mean none of these methods are hit?

        MainWindow(QMainWindow) -> centralwidget(QWidget) -> stackedWidget(QStackedWidget) -> page3(QWidget) -> frame_12(QFrame) -> frame_17(Qframe).

        You say frame_12 is a QFrame (perhaps created in Designer?). But your class is DropImages, derived from QFrame. So this would be a third frame level? May I suggest you start by, say, setting the background color of your DropImages to red so that you can at least it is there and what area it covers?

        fabriciokashF Offline
        fabriciokashF Offline
        fabriciokash
        wrote on last edited by
        #3

        @JonB said in Trying to implement a drop function on a QFrame, help please!:

        Do you mean none of these methods are hit?

        You say frame_12 is a QFrame (perhaps created in Designer?). But your class is DropImages, derived from QFrame. So this would be a third frame level? May I suggest you start by, say, setting the background color of your DropImages to red so that you can at least it is there and what area it covers?

        Yes, these methods was not working. But i found the enabled area using your suggestion and after tried to drop a file, it works! Thank you! I was trying to drop into a wrong area...

        But I found another problem. After setting the background area color, only part of the frame was painted red. This means that only this part of the frame is enabled to drop files. This part is a rectangle in the upper left corner of the frame and reduced in size. While the frame size is (800,200), the red colored part is about (120, 40) size. Can you help me with this problem?

        JonBJ 1 Reply Last reply
        0
        • fabriciokashF fabriciokash

          @JonB said in Trying to implement a drop function on a QFrame, help please!:

          Do you mean none of these methods are hit?

          You say frame_12 is a QFrame (perhaps created in Designer?). But your class is DropImages, derived from QFrame. So this would be a third frame level? May I suggest you start by, say, setting the background color of your DropImages to red so that you can at least it is there and what area it covers?

          Yes, these methods was not working. But i found the enabled area using your suggestion and after tried to drop a file, it works! Thank you! I was trying to drop into a wrong area...

          But I found another problem. After setting the background area color, only part of the frame was painted red. This means that only this part of the frame is enabled to drop files. This part is a rectangle in the upper left corner of the frame and reduced in size. While the frame size is (800,200), the red colored part is about (120, 40) size. Can you help me with this problem?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @fabriciokash
          Since the frame is empty (has no content) I would guess it could be any size. I guess you could set a fixed size, or minimum sizes, or presumably best check its sizePolicy, you want it to fill its parent, I don't know what that is for a QFrame.

          1 Reply Last reply
          1
          • fabriciokashF fabriciokash

            In the mainwindow.ui file, the Qframe that I need to enable the drop function is organized as follows:

            MainWindow(QMainWindow) -> centralwidget(QWidget) -> stackedWidget(QStackedWidget) -> page3(QWidget) -> frame_12(QFrame) -> frame_17(Qframe).

            The last one, frame_17, is the frame where i need to drop zip files. Trying to figure out in internet how to do it, I did this:

            /_____________________________________________
            dropimages.h

            #ifndef DROPIMAGES_H
            #define DROPIMAGES_H
            
            #include <QWidget>
            #include <QFrame>
            
            class DropImages : public QFrame
            {
            
            public:
                explicit DropImages(QWidget *parent = nullptr);
            
            protected:
                void dragEnterEvent(QDragEnterEvent *event) override;
            
                void dragMoveEvent(QDragMoveEvent *event) override;
            
                void dropEvent(QDropEvent *event) override;
            };
            
            #endif // DROPIMAGES_H
            

            /_____________________________________________

            dropimages.cpp

            #include "dropimages.h"
            
            #include <QDrag>
            #include <QDragEnterEvent>
            #include <QMimeData>
            
            DropImages::DropImages(QWidget *parent)
                : QFrame(parent)
            {
                setAcceptDrops(true);
            }
            
            void DropImages::dragEnterEvent(QDragEnterEvent *event)
            {
                printf("cccccc\n"); // for test
                event->accept();
                if(event->mimeData()->hasUrls())
                    event->acceptProposedAction();
            }
            
            void DropImages::dragMoveEvent(QDragMoveEvent *event)
            {
                printf("bbbb\n"); // for test
                event->accept();
                if(event->mimeData()->hasUrls())
                {
                    event->acceptProposedAction();
                }
            }
            
            void DropImages::dropEvent(QDropEvent *event)
            {
                printf("aaaaaa\n"); // for test
                event->accept();
                if(event->mimeData()->hasUrls())
                {
                    foreach(QUrl url, event->mimeData()->urls())
                    {
                        printf(url.toLocalFile().toStdString().c_str());
                    }
                }
            }
            

            /_____________________________________________

            mainwindow.cpp

            inside class implementation:
            DropImages *uploadedImages = new DropImages(ui->frame_17);

            /_____________________________________________

            But nothing is working. Can someone help me please?

            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote on last edited by Pl45m4
            #5

            @fabriciokash

            Have a look at this topic and my replies there.
            It seems that you don't create a QDrag object which will transfer the mime data.


            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            JonBJ fabriciokashF 2 Replies Last reply
            2
            • Pl45m4P Pl45m4

              @fabriciokash

              Have a look at this topic and my replies there.
              It seems that you don't create a QDrag object which will transfer the mime data.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @Pl45m4
              I have never done d&d. Your post is for QGraphicsScene, I presume what you said there about QDrag object is just as relevant here? [You wrote "QDrop object" above, but you meant QDrag, right?]

              I came across Qt's Drop Site Example. Is that relevant for @fabriciokash ? That doesn't seem to use any QDrag object, yet it's handling MIME data, is it a different approach from yours?

              1 Reply Last reply
              2
              • Pl45m4P Pl45m4

                @fabriciokash

                Have a look at this topic and my replies there.
                It seems that you don't create a QDrag object which will transfer the mime data.

                fabriciokashF Offline
                fabriciokashF Offline
                fabriciokash
                wrote on last edited by fabriciokash
                #7

                @Pl45m4

                Thanks for suggestion! But for while thats all i need in this moment. I'll see the topic and learn about, thanks.

                @JonB

                I fixed that too, got it! haha. I just used the method setFixedSize. its all i need at the moment, thanks!

                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