file "game.h": < /p>
Код: Выделить всё
#ifndef GAME_H
#define GAME_H
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
namespace Ui {
class game;
}
class game : public QWidget
{
Q_OBJECT
public:
explicit game(QWidget *parent = 0);
~game();
virtual void keyPressEvent(QKeyEvent *);
}
< /code>
и источник CPP < /p>
void game::keyPressEvent(QKeyEvent *e){
switch(e->key())
{
case Qt::Key_Left :{
this->player->moveBy(-5,0);
break;
}
case Qt::Key_Right :{
this->player->moveBy(5,0);
break;
}
}
this->player->update();
}
< /code>
и в Mainwindow.cpp I нажимает кнопку воспроизведения, которая выполняет этот код: < /p>
void MainWindow::on_Play_clicked()
{
game *Gioco=new game;
Gioco->show();
Gioco->move(300,0);
}
Подробнее здесь: https://stackoverflow.com/questions/266 ... -dont-work