steadi
13th October 2012, 18:22
Hello,
I am still pretty new to Qt and it is pretty different from most of the editors I have ever used before. I have started a simple project - When you click on a QGraphicsScene it draws a red background. However, upon clicking on the scene it crashes the program.
Can anyone see where I went wrong, for the life of me I cannot figure this one out?
Scene Class:
class scene2 : public QGraphicsScene
{
#include <QMessageBox>
public:
QGraphicsScene *scene;
void mousePressEvent(QGraphicsSceneMouseEvent *event);
};
Set's Scene To View:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
scene = new scene2;
ui->GraphicsMap->setScene(scene);
scene->setSceneRect(0,0,900,900);
}
On Click:
void scene2::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
QBrush whiteBrush(Qt::red);
scene->setBackgroundBrush(whiteBrush);
}
Thanks for any help guys,
Matt <Noob>
I am still pretty new to Qt and it is pretty different from most of the editors I have ever used before. I have started a simple project - When you click on a QGraphicsScene it draws a red background. However, upon clicking on the scene it crashes the program.
Can anyone see where I went wrong, for the life of me I cannot figure this one out?
Scene Class:
class scene2 : public QGraphicsScene
{
#include <QMessageBox>
public:
QGraphicsScene *scene;
void mousePressEvent(QGraphicsSceneMouseEvent *event);
};
Set's Scene To View:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
scene = new scene2;
ui->GraphicsMap->setScene(scene);
scene->setSceneRect(0,0,900,900);
}
On Click:
void scene2::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
QBrush whiteBrush(Qt::red);
scene->setBackgroundBrush(whiteBrush);
}
Thanks for any help guys,
Matt <Noob>