Deactivate mouse press event
-
Hello,
I have to functions in my code, they look like this:
@void MainWindow::x_slice_extract()
{
.......code....
}@@void MainWindow::mousejustpressed(int x,int y)
{
......code...
}@The first function (x_slice_extract()) is used to display an image1 in a QGraphicsScene. The second function (mousejustpressed(int x, int y)) is a press mouse event in which every time I press the mouse I call this function and I create an other image2, which I want to display it in the same QGraphicsScene. When I first display my image1 in the QGraphicsScene and when I press the mouse I get the image2 in my QGraphicsScene. But, after pressing the button, and running again the function x_slice_extract(), I should get again image1, but still I have image2 in the QGraphicsScene. Could somebody help me with this problem? When I activate a mouse event, how I could deactivate it?
-
While I am doing debuging, I have noticed that when my QGraphicsScene has already image1, when I press the button and insert in the mouse press event function, then the compiler can't get that has already a pixmapItem, but understands that QGraphicsScene is empty. I think this is the mistake. Could somebody help me to solve it?
@void MainWindow::x_slice_extract()
{
.......code....static QGraphicsPixmapItem* pixmapItem;
if (!pixmapItem) {
QPixmap tmpmap (QPixmap("y.png")); pixmapItem = scene_y->addPixmap ( tmpmap.scaled (size_x,size_y) ); ui->graphicsView_y->setScene(scene_y); } else {
QPixmap tmpmap (QPixmap("y.png"));
pixmapItem->setPixmap(tmpmap.scaled ( size_x,size_y));
}
}@@void MainWindow::mousejustpressed(int x,int y)
{
.......code....static QGraphicsPixmapItem* pixmapItem;
if (!pixmapItem) {
QPixmap tmpmap (QPixmap("y.png")); pixmapItem = scene_y->addPixmap ( tmpmap.scaled (size_x,size_y) ); ui->graphicsView_y->setScene(scene_y); } else {
QPixmap tmpmap (QPixmap("y.png"));
pixmapItem->setPixmap(tmpmap.scaled ( size_x,size_y));
}
}@ -
If you need only one pixmap to be shown at any point of time( if I understood your problem correctly), then why don't you maintain a QGraphicsPixmapItem say currentPixmapItem which is the ONLY pixmap item added to the scene. In the corresponding methods, just set the pixmap of the currenPixmapItem, so that it changes accordingly.