我遇到了mousePressEvent(QGraphicsSceneMouseEvent *event)
问题,的确,可点击区域看起来很小,并且偏离了它所链接的QGraphicsPixmapItem
。Qt“mousePressEvent”修改了可点击区域
红线是其中QGraphicsPixmapItem可点击。
我该如何居中并最终使其变大并改变它的形状?
这里是我的代码的部分,可以是有用的:
在player.h
class Player:public QObject, public QGraphicsPixmapItem{
Q_OBJECT
public:
Player();
void place_player(int x, int y);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
};
在player.cpp
Player::Player(): QGraphicsPixmapItem(){
}
void Player::place_player(int x,int y)
{
this->setPixmap(QPixmap("test.png"));
this->setPos(x,y);
game->scene->addItem(this);
}
void Player::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
qDebug()<< event;
};
在game.cpp
Game::Game(){
setFixedSize(1600,900);
scene = new QGraphicsScene(this);
scene->setSceneRect(0,0,1600,900);
setScene(scene);
}
void Game::start(){
player1 = new Player();
player1->place_player(300,300);
}
void Game::mousePressEvent(QMouseEvent *event)
{
QGraphicsView::mousePressEvent(event);
}
最后, main.cpp中
int main(int argc, char *argv[]){
QApplication a(argc, argv);
game = new Game();
game->show();
game->start();
return a.exec();
}
非常感谢您的帮助
非常感谢你:) – 2015-03-31 20:43:06