Quantcast
Channel: Jobs
Viewing all articles
Browse latest Browse all 18427

[SOLVED] Help with keypress event

$
0
0
Hi all! I am trying to have a keypress event in my mainwindow. But on running the application, no event occurs when I press the specific key. Can you please have a look at my code down below and guide me if I’m wrong? Thanks. mainwindow.h #include <QKeyEvent>     namespace Ui { class MainWindow; }   class MainWindow: public QMainWindow {     Q_OBJECT     public:     explicit MainWindow(QWidget *parent = 0);     ~MainWindow();   protected:     void keypress(QKeyEvent *e);   }; #endif my mainwindow.cpp #include "MainWindow.h" #include "ui_MainWindow.h"     MainWindow::MainWindow(QWidget *parent) :     QMainWindow(parent),     ui(new Ui::MainWindow) {     ui->setupUi(this); }   void MainWindow::keypress(QKeyEvent *keyevent) {     if (keyevent->key() == Qt::Key_Escape)     this->close(); }   ProgramBanner::~ProgramBanner() {     delete ui; }

Viewing all articles
Browse latest Browse all 18427

Trending Articles