Results 1 to 3 of 3

Thread: Bypass key when edit in QListView

  1. #1
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Bypass key when edit in QListView

    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 :
    Qt Code:
    1. virtual void keyPressEvent( QKeyEvent* event )
    2. {
    3. QListView::keyPressEvent( event );
    4. if( ( event->key() == Qt::Key_Enter ) || ( event->key() == Qt::Key_Return ) )
    5. ActivateSelectedItem();
    6. }
    To copy to clipboard, switch view to plain text mode 
    How bypass the action during edit of the item ?
    Thanks for the help

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Bypass key when edit in QListView

    Maybe by including a check for EditingState in that if condition?

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    Kryzon (23rd January 2015)

  4. #3
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Bypass key when edit in QListView

    Damn I tried that from start but missed one parenthese in the "if" to do "a && (b || c)" and not "a && b || c" :
    Qt Code:
    1. virtual void keyPressEvent( QKeyEvent* event )
    2. {
    3. QListView::keyPressEvent( event );
    4. if( ( state() != QAbstractItemView::EditingState ) && ( ( event->key() == Qt::Key_Enter ) || ( event->key() == Qt::Key_Return ) ) )
    5. ActivateSelectedItem();
    6. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 2
    Last Post: 22nd January 2015, 14:58
  2. Bypass MessageBox QFileSystemModel
    By Alundra in forum Qt Programming
    Replies: 3
    Last Post: 8th June 2014, 22:47
  3. how to bypass repainting a containing widget?
    By RolandHughes in forum Qt Programming
    Replies: 3
    Last Post: 31st January 2014, 10:42
  4. Adding validation to a QListView's edit mode
    By MattT in forum Qt Programming
    Replies: 10
    Last Post: 1st August 2010, 01:53
  5. use GNU make entirely and bypass qmake?
    By kevinm in forum Qt Programming
    Replies: 1
    Last Post: 5th September 2008, 22:40

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
  •  
Qt is a trademark of The Qt Company.