QListWidget : Event on item click

后端 未结 2 854
-上瘾入骨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.
        }
    }
    
    0 讨论(0)
  • 2021-01-12 07:11

    QListWidget has a signal QListWidget::itemPressed(QListWidgetItem *item) that will tell you which item was clicked. You can connect this signal to your own slot. There are also other related signals. See the documentation.

    0 讨论(0)
提交回复
热议问题