Well, I guess I found myself another problem.
The event handler I just implemented doesn't have the scope to alter the scene or the items inside the scene. Since the scene and the items are implemented in MainWindow, i tried to inherit the graphicsScene from MainWindow. Then the scope problem is resolved but their is no output Window.
This is the Code in MainWindow.h:
...
graphicsScene *scene;
void toggle(int ,int);
...
};
{
public:
};
class MainWindow : public QMainWindow {
...
QGraphicsRectItem *obstRect[Xgrid][Ygrid];
graphicsScene *scene;
void toggle(int ,int);
...
};
class graphicsScene : public QGraphicsScene
{
public:
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
};
To copy to clipboard, switch view to plain text mode
The Code in MainWindow.cpp is like:
ui(new Ui::MainWindow)
{
for(int i=0;i<Xgrid;i++)
for(int j=0;j<Ygrid;j++)
obstRect[i][j]->setBrush(Qt::white);
}
scene = new graphicsScene();
scene->setSceneRect(0,0,310,310);
for(int i=0;i<Xgrid;i++)
for(int j=0;j<Ygrid;j++)
scene->addItem(obstRect[i][j]);
ui->graphicsView->setScene(scene);
...
}
{
...
//the part were error arise
toggle(x,y);
qDebug()<<x<<y;
...
}
void MainWindow::toggle(int x, int y)
{
...
}
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
ui(new Ui::MainWindow)
{
for(int i=0;i<Xgrid;i++)
for(int j=0;j<Ygrid;j++)
{ obstRect[i][j] =new QGraphicsRectItem();
obstRect[i][j]->setBrush(Qt::white);
}
scene = new graphicsScene();
scene->setSceneRect(0,0,310,310);
for(int i=0;i<Xgrid;i++)
for(int j=0;j<Ygrid;j++)
scene->addItem(obstRect[i][j]);
ui->graphicsView->setScene(scene);
...
}
void graphicsScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsScene::mouseDoubleClickEvent(event);
...
//the part were error arise
toggle(x,y);
qDebug()<<x<<y;
...
}
void MainWindow::toggle(int x, int y)
{
...
}
To copy to clipboard, switch view to plain text mode
please gimme some solutions. Its driving me mad.
Bookmarks