I know, there is more thread about that in this forum. I looked all of them, but still i cant work it.
Vista Business
Qt SDK 2010.05
Qt Creator 2.0.1
I'm just trying to get which key is pressed.
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "ui_mainwindow.h"
class MainWindow
: public QMainWindow,
private Ui
::MainWindow{
Q_OBJECT
private:
Ui::MainWindow *gui;
public:
explicit MainWindow
(QWidget *parent
= 0);
protected:
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "ui_mainwindow.h"
class MainWindow : public QMainWindow, private Ui::MainWindow
{
Q_OBJECT
private:
Ui::MainWindow *gui;
public:
explicit MainWindow(QWidget *parent = 0);
protected:
bool keypres(QKeyEvent *keyevent);
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
mainwindow.cpp
#include "mainwindow.h"
#include <QKeyEvent>
#include <QDebug>
MainWindow
::MainWindow(QWidget *parent
) : gui->setupUi(this);
gui->textEdit->installEventFilter(this);
}
bool MainWindow
::keypres(QKeyEvent *keyevent
) {
if (keyevent->key()==Qt::Key_W)
{
qDebug() << "hi";
}
}
#include "mainwindow.h"
#include <QKeyEvent>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),gui(new Ui::MainWindow){
gui->setupUi(this);
gui->textEdit->installEventFilter(this);
}
bool MainWindow::keypres(QKeyEvent *keyevent)
{
if (keyevent->key()==Qt::Key_W)
{
qDebug() << "hi";
}
}
To copy to clipboard, switch view to plain text mode
main.cpp
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
MainWindow w;
w.show();
return a.exec();
}
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
I just want to control keys and key events.
Regards.
Bookmarks