PDA

View Full Version : Bypass key when edit in QListView



Alundra
23rd January 2015, 01:17
Hi,
I have inherited QListView to have keypress event to handle the enter/return key.
All works fine but one problem exists, if you enter during edit of an item, that does the action.
Here the actual code :

virtual void keyPressEvent( QKeyEvent* event )
{
QListView::keyPressEvent( event );
if( ( event->key() == Qt::Key_Enter ) || ( event->key() == Qt::Key_Return ) )
ActivateSelectedItem();
}
How bypass the action during edit of the item ?
Thanks for the help

anda_skoa
23rd January 2015, 08:57
Maybe by including a check for EditingState in that if condition?

Cheers,
_

Alundra
23rd January 2015, 13:51
Damn I tried that from start but missed one parenthese in the "if" to do "a && (b || c)" and not "a && b || c" :

virtual void keyPressEvent( QKeyEvent* event )
{
QListView::keyPressEvent( event );
if( ( state() != QAbstractItemView::EditingState ) && ( ( event->key() == Qt::Key_Enter ) || ( event->key() == Qt::Key_Return ) ) )
ActivateSelectedItem();
}