PDA

View Full Version : [QT3] QListView and Key_Delete - doesn't work?



InZone
26th January 2006, 10:05
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


void CEngravingDialog::keyPressEvent( QKeyEvent *event )
{
if( listViewElements->hasMouse() )
{
switch( event->key() )
{
case Key_Delete: //Delete if item in listview is selected
ButtonDelete();
break;
default:
QWidget::keyPressEvent( event );
}
}
}

high_flyer
26th January 2006, 11:48
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.

BrainB0ne
26th January 2006, 15:49
I made such an option for myself :)

I subclassed QListView and then reimplemented the keyPressEvent..

Like this...



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++;
}
}
}

QListView::keyPressEvent(event);
}


I think this works fine for single selection :)
It's a different approach than yours, but it's an idea :)