Basically, what I have is the following :
A QListWidget, with some items in it like this :
ListMail
is my QListWidget.
In this QListWidget, I have elements like : "Mail 1", "Mail 2", ...
And I don't have any idea, how can I make a signal on (for example) "Mail 1" bind to a slot(onClick) or something like that.
I already tried things like :
connect(ui->listMail->selectedItems(0), SIGNAL(triggered()), this, SLOT(openMessage())
, but it doesn't work at all...
Any help ?
Thanks !
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.
}
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With