Custom QListWidget

From Qt Wiki
Revision as of 15:32, 3 March 2015 by AutoSpider (talk | contribs) (Add "cleanup" tag)
Jump to: navigation, search

Custom QListWidget

Small snippet showing how to override dropEvent method on a custom QListWidget.

  1. First create a Qt Gui Application using Qt Creator and add a QListWidget to it.
  2. Create the below given MyListWidget.h and MyListWidget.cpp files.
  3. Right click on the QListWidget created in the Form designer and Promote it to MyListWidget
  4. When you run the application, if you drop something on MyListWidget, you will first see the debug msg (dropEvent of MyListWidget), and then it calls the dropEvent of the QListWidget …

The header file

  1. ifndef MYLISTWIDGET_H
  2. define MYLISTWIDGET_H
  1. include <QListWidget>

class MyListWidget : public QListWidget {



MyListWidget(QWidget *parent = 0);


void dropEvent(QDropEvent *event);


  1. endif // MYLISTWIDGET_H

The cpp file

  1. include "mylistwidget.h"
  2. include <QDebug>

MyListWidget::MyListWidget(QWidget *parent)

: QListWidget(parent)




void MyListWidget::dropEvent(QDropEvent *event) {

qDebug() << "This is my custom dropEvent() method!";