Minha classe:
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;
};
Minha Função:
void Jogador::keyPressEvent(QKeyEvent* event) {
QWidget::keyPressEvent(event);
switch (event->key()) {
case Qt::Key_Up:
x+=20;
repaint();
break;
default:
break;
}
}
A pergunta é: eu vou conseguir fazer o evento de teclas funcionar em uma classe que herda de QWidget
, ou somente QFrame
?
meu main está assim:
#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;
}