0
My class:
class Jogador : public QWidget {
Q_OBJECT
public:
Jogador(QWidget* parent = NULL);
void draw();
void paintEvent(QPaintEvent* event);
void keyPressEvent(QKeyEvent* event);
private:
int x,y,w,h;
QVBoxLayout* layout;
};
My Function:
void Jogador::keyPressEvent(QKeyEvent* event) {
QWidget::keyPressEvent(event);
switch (event->key()) {
case Qt::Key_Up:
x+=20;
repaint();
break;
default:
break;
}
}
The question is: will I be able to make the keystroke event work in a class that inherits from QWidget
, or only QFrame
?
my main is like this:
#include<QApplication>
#include<tabuleiro.h>
#include<jogador.h>
#include<QWidget>
int main(int argc, char* argv[]){
QApplication app(argc, argv);
QWidget window;
Tabuleiro t(&window);
Jogador j(&window);
window.show();
return app.exec();
return 0;
}
Check out my main, I think there must be something wrong. because I can not make call the Keyevent
– Kaue