Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Drag and drop items from one list widget to another

    General and Desktop
    2
    2
    1507
    Loading More Posts
    • 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.
    • I
      Im_ArunV last edited by A Former User

      how to implement drag and drop items from one QListWidget to another without using predefined Qt Designer settings,atleast provide some hint how to implement drop event in QListWidget??
      wanted to implement a feature if listwidget contains drop item(lets say "abc") already wanna rename newly dropped item to abc_2 for this not able to find the dropevent on a listwidget

      1 Reply Last reply Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by mrjj

        Hi
        You would override the dragX function and use startDrag to begin the operation.

        please see this
        http://doc.qt.io/qt-5/qtwidgets-draganddrop-puzzle-example.html

        The area to the left is a list and code shows how its done.

        class PiecesList : public QListWidget
        {
            Q_OBJECT
        
        public:
            explicit PiecesList(int pieceSize, QWidget *parent = 0);
            void addPiece(QPixmap pixmap, QPoint location);
        
            static QString puzzleMimeType() { return QStringLiteral("image/x-puzzle-piece"); }
        
        protected:
            void dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE;
            void dragMoveEvent(QDragMoveEvent *event) Q_DECL_OVERRIDE;
            void dropEvent(QDropEvent *event) Q_DECL_OVERRIDE;
            void startDrag(Qt::DropActions supportedActions) Q_DECL_OVERRIDE;
        
            int m_PieceSize;
        };
        
        1 Reply Last reply Reply Quote 0
        • First post
          Last post