QListWidget Help



  • Hi Guys
    How do i use QListWidget Item Click Event ?



  • Hi

    You can connect the signal itemClicked(QListWidgetItem* item) to a slot of yours. Then, you'll have access to the clicked item (the parameter of the emitted signal).

    A really simple example:

    // In MyClass.h :
    ...
    class MyClass : public QWidget
    {
        public:
            MyClass(QWidget* parent = 0);
        ...
        public slots:
            void on_listWidget_itemClicked(QListWidgetItem* item);
        ...
    };
    
    // In MyClass.cpp
    
    ...
    #include "MyClass.h"
    ...
    MyClass:MyClass(QWidget* parent) : QWidget(parent)
    {
        QListWidget* listWidget = new QListWidget(this);
        connect(listWidget, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(on_listWidget_itemClicked(QListWidgetItem*)));
    }
    ...
    MyClass::on_listWidget_itemClicked(QListWidgetItem* item)
    {
        // Use as you wish the item given in parameter, i.e. the clicked item.
    }
    ...
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.