Results 1 to 9 of 9

Thread: keyPressEvent doesn't work

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2012
    Posts
    232
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Platforms
    Windows Android

    Default keyPressEvent doesn't work

    Hi

    This is my steps:

    - I created the "Qt Widget Application"
    - I opened the "MainWindow.ui" file and put on it the "mdiArea"
    - I created the "Qt Designer Form Class" and wrote in the "MainWindow.h" and "MainWindow.cpp" files:
    Qt Code:
    1. private:
    2. Ui::MainWindow *ui;
    3. FirstWindow *m_firstWindow;
    4. SecondWindow *m_secondWindow;
    5. ThirdWindow *m_thirdWindow;
    To copy to clipboard, switch view to plain text mode 

    MainWindow.cpp
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6.  
    7. m_firstWindow = new FirstWindow;
    8. m_secondWindow = new SecondWindow;
    9. m_thirdWindow = new ThirdWindow;
    10.  
    11. QMdiSubWindow *w1 = ui->mdiArea->addSubWindow( m_firstWindow );
    12. ui->mdiArea->addSubWindow( m_secondWindow );
    13. ui->mdiArea->addSubWindow( m_thirdWindow );
    14.  
    15. ui->mdiArea->cascadeSubWindows();
    16.  
    17. w1->resize( 500, 500 );
    18. }
    To copy to clipboard, switch view to plain text mode 

    - I opened "FirstWindow.h" and "FirstWindow.cpp" files and wrote:
    FirstWindow.h
    Qt Code:
    1. private:
    2. Ui::FirstWindow *ui;
    3. void keyPressEvent( QKeyEvent *event );
    4. };
    To copy to clipboard, switch view to plain text mode 

    FirstWindow.cpp
    Qt Code:
    1. void FirstWindow::keyPressEvent(QKeyEvent *event)
    2. {
    3. qDebug() << "keyPressEvent";
    4. }
    To copy to clipboard, switch view to plain text mode 

    - I ran the application and pressed on the keys. But I didn't see the text "keyPressEvent" on the "Application Output"

    Thank you!

  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: keyPressEvent doesn't work

    Does the FirstWindow instance have focus when you press a key?

    Key events are delivered to the widget which has keyboard focus, see QApplication::focusWidget().

    Cheers,
    _

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

    8Observer8 (24th August 2014)

Similar Threads

  1. keypressevent dont work when MainWindow is minimized
    By spitty_cash in forum Qt Programming
    Replies: 0
    Last Post: 17th October 2011, 16:13
  2. Screenshot example doesn't work on Mac OSX
    By Damiano in forum Qt Programming
    Replies: 0
    Last Post: 19th January 2011, 11:17
  3. Example in Qt labs doesn't work
    By matko in forum Newbie
    Replies: 1
    Last Post: 19th November 2009, 18:59
  4. QGLWidget, keyPressEvent does not work
    By ricardo in forum Qt Programming
    Replies: 7
    Last Post: 3rd July 2009, 10:28
  5. setTabStopWidth doesn't work
    By discostu in forum Qt Programming
    Replies: 3
    Last Post: 19th November 2007, 08:29

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.