Results 1 to 3 of 3

Thread: [QT3] QListView and Key_Delete - doesn't work?

  1. #1
    Join Date
    Jan 2006
    Posts
    1
    Qt products
    Qt3
    Platforms
    Windows

    Default [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

    Qt Code:
    1. void CEngravingDialog::keyPressEvent( QKeyEvent *event )
    2. {
    3. if( listViewElements->hasMouse() )
    4. {
    5. switch( event->key() )
    6. {
    7. case Key_Delete: //Delete if item in listview is selected
    8. ButtonDelete();
    9. break;
    10. default:
    11. QWidget::keyPressEvent( event );
    12. }
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    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.

  3. #3
    Join Date
    Jan 2006
    Location
    Netherlands
    Posts
    56
    Thanks
    10
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default 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...

    Qt Code:
    1. void MyListView::keyPressEvent( QKeyEvent *event )
    2. {
    3. QListViewItemIterator it(this);
    4.  
    5. if ( (event->key() == Qt::Key_Delete) )
    6. {
    7. while ( it.current() )
    8. {
    9. if( it.current()->isSelected() )
    10. {
    11. ButtonDelete( it.current() );
    12. break;
    13. }
    14. else
    15. {
    16. it++;
    17. }
    18. }
    19. }
    20.  
    21. QListView::keyPressEvent(event);
    22. }
    To copy to clipboard, switch view to plain text mode 

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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.