QListWidget : Event on item click

后端 未结 2 927
-上瘾入骨i
-上瘾入骨i 2021-01-12 06:42

Basically, what I have is the following :

A QListWidget, with some items in it like this :

ListMail is my QListWidget. In this QListWidget, I ha

2条回答
  •  没有蜡笔的小新
    2021-01-12 07:08

    You must bind to the itemClicked signal. The signal will provide you with a QListWidgetItem* which is the item that was clicked. You can then examine it and check if it is the first one:

    MyClass::MyClass(QWidget* parent)
        : QWidget(parent)
    {
        connect(ui->listMail, SIGNAL(itemClicked(QListWidgetItem*)), 
                this, SLOT(onListMailItemClicked(QListWidgetItem*)));
    }
    
    void MyClass::onListMailItemClicked(QListWidgetItem* item)
    {
        if (ui->listMail->item(0) == item) {
            // This is the first item.
        }
    }
    

提交回复
热议问题