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. [Solved] overloading dropEvent
Forum Updated to NodeBB v4.3 + New Features

[Solved] overloading dropEvent

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 5.8k 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.
  • C Offline
    C Offline
    countzero
    wrote on last edited by
    #1

    I am working on a simple window app. I have two qlistwidgets and I want to overload the dropEvent for one of them.
    @namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow {
    Q_OBJECT
    public:
    MainWindow(QWidget *parent = 0);
    ~MainWindow();

    protected:
    void changeEvent(QEvent *e);
    virtual void dropEvent(QDropEvent *e);

    private:
    Ui::MainWindow *ui;

    private slots:
    void on_createString_clicked();
    };@

    Ui::MainWindow *ui; is the main class that contains all the widgets. the ui_window.h file is generated by qtcreator.

    All the examples that I have seen put the function void dropEvent in the "your class" header file(the code above).

    I have tried this but it does not seem to work. It seems like I am doing this a level to high, but I don't know where to put it since you should not edit the ui_window.h because it will get overwritten the next time you do something in qtcreator.

    Any help would be great.
    Thanks

    1 Reply Last reply
    0
    • ? This user is from outside of this forum
      ? This user is from outside of this forum
      Guest
      wrote on last edited by
      #2

      I think you could try this ..

      Extend QListWidget and override the dropEvent. Then in your designer, promote the QListWidget to the new class you created. That should work

      1 Reply Last reply
      0
      • C Offline
        C Offline
        countzero
        wrote on last edited by
        #3

        I have created a new class and promoted my QListWidget to the new class but now it does not appear when I run the program. It is viewable in UI designer and the following code is generated.
        @
        CustomProtocol = new CustomListWidget(centralWidget);
        CustomProtocol->setObjectName(QString::fromUtf8("CustomProtocol"));
        CustomProtocol->setGeometry(QRect(440, 20, 300, 275));
        CustomProtocol->setDragEnabled(true);
        CustomProtocol->setDragDropMode(QAbstractItemView::DragDrop);
        CustomProtocol->setDefaultDropAction(Qt::MoveAction);
        @

        Does the constructor the new class need anything? It is currently blank.

        Thanks,

        1 Reply Last reply
        0
        • ? This user is from outside of this forum
          ? This user is from outside of this forum
          Guest
          wrote on last edited by
          #4

          hope "this wiki page":http://developer.qt.nokia.com/wiki/Custom_QListWidget helps

          1 Reply Last reply
          0
          • C Offline
            C Offline
            countzero
            wrote on last edited by
            #5

            Thanks I figured it out. I missed the : QListWidget(parent) so it was not inheriting the correct functions.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              gurudutt
              wrote on last edited by
              #6

              This is really helpful

              Thank you :)

              Release Manager - Qt Development Frameworks

              1 Reply Last reply
              0
              • ? This user is from outside of this forum
                ? This user is from outside of this forum
                Guest
                wrote on last edited by
                #7

                glad it worked

                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