I am working on a project in Qt 4.7 where a have a QListWidget
which needs to perform a certain function when an item from the list is selected. The particular function isn't important here, so for this example let's say it is to print the value to std::cout
. I have it right now so that it does this when a value is double-clicked, like so:
connect(ui->myList, SIGNAL(doubleClicked(QModelIndex)),
this, SLOT(printChoice(QModelIndex)));
...
void MyClass::printChoice(QModelIndex index)
{
std::cout << ui->myList->model()->data(index).toString();
}
This code works perfectly. However, my project lead said they would like it to enter this slot for whatever row of the list is currently selected when the user clicked the F2 key. I do not know of any signals that are emitted for these keys, and looking around the web hasn't helped much. Does anyone know of a way to do this? Thanks!
EDIT: I've found that hitting F2 while a value is selected automatically puts that row into edit mode (it must be built in to Qt) but I still need to know how to trigger a slot when that occurs.
EDIT 2: I'm getting closer. I found I could make a slot in MyClass
called keyPressEvent(QKeyEvent *event)
that will register whenever certain keys are hit, including the fX keys. However, I still cannot find a way to differentiate which key triggered it, and how to make sure it was F2