PDA

View Full Version : QListWidget activate all selected items



Alundra
20th January 2016, 16:23
Hi,
QListWidget has a behabior for the activation key but that only activate the last selected and not all selected items.
I tried to find the activation key sequence in the qt doc to overwrite the action but nothing found.
How achieve that correctly ?
Thanks

wysota
20th January 2016, 17:15
Reimplement keyPressEvent() and perform activation for each of the items.

Alundra
21st January 2016, 00:07
This is what I did at the end, I did like that :

virtual void keyPressEvent( QKeyEvent* event ) override
{
// Activate all selected items when enter or return.
if( ( event->key() == Qt::Key_Enter ) || ( event->key() == Qt::Key_Return ) )
{
// Call itemActivated for each item needed.
...
event->accept();
return;
}

// Alphanumeric keys.
if( event->text().isEmpty() == false )
QListWidget::keyPressEvent( event );
}
That works good but the Qt doc says mac uses another key, but maybe enter and return works good for all plateform at the end.
If I press multiple time one alphanumeric key, the action is stopped, I have no answer why.