Crashes When Using QGraphicsScene?
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:
Code:
{
#include <QMessageBox>
public:
};
Set's Scene To View:
Code:
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
scene = new scene2;
ui->GraphicsMap->setScene(scene);
scene->setSceneRect(0,0,900,900);
}
On Click:
Code:
{
scene->setBackgroundBrush(whiteBrush);
}
Thanks for any help guys,
Matt <Noob>
Re: Crashes When Using QGraphicsScene?
Please post the whole project, if you can. What you posted seems ok, it shouldn't cause a crash.
Re: Crashes When Using QGraphicsScene?
Thanks for the help man,
It appears to be working now. It turns out that I was actually decalring two scene variables named scene and each one with there own class that was cancelling out the others commands and crashing the system.
Now that I have that working - I can click on the scene and get a red background but I cannot drag items that have the ItemIsMovable flag on, why is this?
Thanks,
Matt
Re: Crashes When Using QGraphicsScene?
Because the flag is implemented in scene's mousePressEvent. You have overriden it without calling the base class implementation, so the code that handles moving items is not called. If you call the base class implementation of the mousePressEvent, all should work fine.