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:
{
#include <QMessageBox>
public:
};
class scene2 : public QGraphicsScene
{
#include <QMessageBox>
public:
QGraphicsScene *scene;
void mousePressEvent(QGraphicsSceneMouseEvent *event);
};
To copy to clipboard, switch view to plain text mode
Set's Scene To View:
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
scene = new scene2;
ui->GraphicsMap->setScene(scene);
scene->setSceneRect(0,0,900,900);
}
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);
}
To copy to clipboard, switch view to plain text mode
On Click:
{
scene->setBackgroundBrush(whiteBrush);
}
void scene2::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
QBrush whiteBrush(Qt::red);
scene->setBackgroundBrush(whiteBrush);
}
To copy to clipboard, switch view to plain text mode
Thanks for any help guys,
Matt <Noob>
Bookmarks