hello,
I currently devoloping a point and click adventure as school project.
But I have a problem with the MouseMoveEvent.
I don't know how to implement that, the rectangle moves where I click with the mouse.
I hope someone understands my problem.
Thanks in advance
Best regards
Basti1990
PS code:
// HEADER FILE
#ifndef GAME_H
#define GAME_H
#include <QEvent>
#include <QKeyEvent>
#include <QApplication>
#include <QGraphicsRectItem>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QPainter>
#include <QPointer>
#include <QVariant>
#include <QDebug>
#include <QBrush>
#include <QPen>
{
Q_OBJECT
public:
explicit Game
(QWidget *parent
= 0);
~Game();
private:
protected:
};
#endif // GAME_H
// CPP FILE
#include "game.h"
{
view->setScene(scene);
rectangle->setRect(0,0,100,100);
QPen blackpen
(Qt
::black);
blackpen.setWidth(6);
rectangle->setPen(blackpen);
rectangle
->setBrush
(QBrush(Qt
::white));
rectangle->setFocus();
scene->addItem(rectangle);
scene->setBackgroundBrush(Qt::blue);
// view->setWindowFlags(Qt::FramelessWindowHint);
view->show();
}
Game::~Game()
{}
{
// SomeThing ?
}
// MAIN FILE
#include "game.h"
#include "menue.h"
#include <QApplication>
int main(int argc, char *argv[])
{
Game w;
w.setVisible(false);
return a.exec();
}
// HEADER FILE
#ifndef GAME_H
#define GAME_H
#include <QEvent>
#include <QKeyEvent>
#include <QApplication>
#include <QGraphicsRectItem>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QPainter>
#include <QPointer>
#include <QVariant>
#include <QDebug>
#include <QBrush>
#include <QPen>
class Game : public QWidget
{
Q_OBJECT
public:
explicit Game(QWidget *parent = 0);
~Game();
private:
QGraphicsScene *scene;
QGraphicsView *view;
QGraphicsRectItem *rectangle;
protected:
void mouseMoveEvent(QMouseEvent *mousevent);
};
#endif // GAME_H
// CPP FILE
#include "game.h"
Game::Game(QWidget *parent)
: QWidget(parent)
{
scene = new QGraphicsScene;
view = new QGraphicsView;
view->setScene(scene);
rectangle = new QGraphicsRectItem;
rectangle->setRect(0,0,100,100);
QPen blackpen(Qt::black);
blackpen.setWidth(6);
rectangle->setPen(blackpen);
rectangle->setBrush(QBrush(Qt::white));
rectangle->setFlag(QGraphicsItem::ItemIsFocusable);
rectangle->setFocus();
scene->addItem(rectangle);
scene->setBackgroundBrush(Qt::blue);
// view->setWindowFlags(Qt::FramelessWindowHint);
view->show();
}
Game::~Game()
{}
void Game::mouseMoveEvent(QMouseEvent *mousevent)
{
// SomeThing ?
}
// MAIN FILE
#include "game.h"
#include "menue.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Game w;
w.setVisible(false);
return a.exec();
}
To copy to clipboard, switch view to plain text mode
PPS sorry for my terrible english
Bookmarks