[QT3] QListView and Key_Delete - doesn't work?
Hi there,
I am trying to get a simple thing running: alowing the user to delete a listviewitem with the "del" key. But it seems that the listview doesn't get that key. Some other keys I tried are not a problem....
It seem that something is catching my keay away?
Any help is welcome
Thanks in advance
Rafael
Code:
void CEngravingDialog
::keyPressEvent( QKeyEvent *event
) {
if( listViewElements->hasMouse() )
{
switch( event->key() )
{
case Key_Delete: //Delete if item in listview is selected
ButtonDelete();
break;
default:
}
}
}
Re: [QT3] QListView and Key_Delete - doesn't work?
you are catching the kePressEvent on the listView through the dialog.
Did you turn on global mouse grabbing?
Try doing the same as you did but with the listView directly.
Re: [QT3] QListView and Key_Delete - doesn't work?
I made such an option for myself :)
I subclassed QListView and then reimplemented the keyPressEvent..
Like this...
Code:
void MyListView
::keyPressEvent( QKeyEvent *event
) {
QListViewItemIterator it(this);
if ( (event->key() == Qt::Key_Delete) )
{
while ( it.current() )
{
if( it.current()->isSelected() )
{
ButtonDelete( it.current() );
break;
}
else
{
it++;
}
}
}
}
I think this works fine for single selection :)
It's a different approach than yours, but it's an idea :)