Results 1 to 3 of 3

Thread: Handling keyPress event such as CTRL+A, CTRL+C on QTableView widgets

  1. #1
    Join Date
    Jun 2012
    Posts
    38
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Handling keyPress event such as CTRL+A, CTRL+C on QTableView widgets

    Hi All,

    I am having some problems implementing the eventFilter for my QTableView (filled with QStandardtems).

    This partially works:


    Qt Code:
    1. ....
    2. //ui->playTableView->installEventFilter(this);
    3. }
    4.  
    5.  
    6. bool MainWindow::eventFilter(QObject *object, QEvent *e)
    7. {
    8. // Get selected text on keypress event ctrl+e
    9. if (object == ui->playTableView) {
    10. if (e->type() == QEvent::KeyPress) {
    11. QKeyEvent *keyEvent = static_cast<QKeyEvent*>(e);
    12. if (keyEvent->key() == Qt::Key_A) {
    13. qDebug() << "CTRL-A Key pressed" << keyEvent->key();
    14. return true;
    15. }
    16. }
    17. }
    18. return true;
    19. }
    To copy to clipboard, switch view to plain text mode 

    But it makes the app very slow, especially filling the QTableView up with data is like 10 times slower.

    What I want to accomplish here is to capture the CTRL-A (Select ALL) keystroke as well as the Arrow Up and Arrow Down when the focus is on the QTableView Widget. I want to keep the default behavior, that all rows in the tableview are selected, but I want to disable some QLineEdits if more than on Row is selected.

    If a user selects with the mouse it is not a problem, since I can capture the clicked and double clicked. But How to I catch the CTRL-A ??

    Can I use QAction for this?

    Hope some one can help me, if possible also with some examples.

    Thanks in advace!

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    506
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Handling keyPress event such as CTRL+A, CTRL+C on QTableView widgets

    Hi, I'm not sure if it is related to your speed problem, but you should not return true at the end of the eventFilter function. Returning true means that the event has been filtered. Normally you'd call your base class' implementation of eventFilter to give it the chance to handle events that your class does not handle.

    Ginsengelf

  3. #3
    Join Date
    Jun 2012
    Posts
    38
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Handling keyPress event such as CTRL+A, CTRL+C on QTableView widgets

    Hi!

    thanks for your prompt answer. I believe that might have been the reason why my eventFilter was so slow. I changed to false, and no appears to be working appropiately!

    Also tried the approach of QAction shotcut. that solution also worked for me for the CTRL+A.

    once again Thanks!

Similar Threads

  1. simultaneous use of ctrl key along with mouse press event.
    By vinod sharma in forum Qt Programming
    Replies: 9
    Last Post: 28th February 2012, 10:09
  2. Handling keypress event in textedit
    By Niamita in forum Qt Programming
    Replies: 1
    Last Post: 14th December 2011, 10:07
  3. How to send a "Ctrl+V" event to a QWebView
    By daudiam in forum Qt Programming
    Replies: 2
    Last Post: 1st December 2010, 09:51
  4. problem with keypress event and QTableView
    By ranna in forum Qt Programming
    Replies: 4
    Last Post: 24th August 2009, 16:13
  5. Replies: 1
    Last Post: 14th September 2008, 23:05

Tags for this Thread

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.