Results 1 to 2 of 2

Thread: Problems with very simple keyPressEvent in MainWindow

  1. #1

    Default Problems with very simple keyPressEvent in MainWindow

    Hello

    I've been trying to add a basic keyboard input handler to my mainwindow. The mainwindow has a few Qlabels and pushbuttons, nothing fancy.

    I've tried adding the following code:

    mainwindow.h
    Qt Code:
    1. protected:
    2. void keyPressEvent(QKeyEvent *event);
    To copy to clipboard, switch view to plain text mode 

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

    But nothing happens when I press a key. I think there's something very simple that I'm missing, but I just can't figure it out. Trust me I've googled quite a bit on the topic but got nowhere. Any help would be greatly appreciated. Thanks.

  2. #2
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Problems with very simple keyPressEvent in MainWindow

    Quote Originally Posted by naizarak View Post

    mainwindow.cpp
    Qt Code:
    1. void MainWindow::keyPressEvent(QKeyEvent *event)
    2. {
    3. std::cout << "pressed";
    4. }
    To copy to clipboard, switch view to plain text mode 
    remove std::cout.
    Qt Code:
    1. #include <QDebug>
    2. qDebug() << "pressed";
    To copy to clipboard, switch view to plain text mode 

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. Problems compiling simple plugin
    By tehr in forum Newbie
    Replies: 0
    Last Post: 14th March 2011, 21:43
  3. Replies: 0
    Last Post: 3rd January 2011, 22:34
  4. Problems with simple Qt Style Sheet
    By Qn00b in forum Qt Programming
    Replies: 3
    Last Post: 14th October 2010, 22:33
  5. Simple DataBase problems
    By briang in forum Newbie
    Replies: 2
    Last Post: 31st December 2009, 09:42

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.