View Full Version : Display images and move them
AL
11th February 2010, 11:12
Hello,
I am developing a checkers game for Mac and Win.
I am displaying each piece in a QLabel in the following way
QLabel *piece = new QLabel("piece",this);
piece->setPixmap(QPixmap("piece.png"));
Now I have to display kings and I would like to overlap two images (piece.png) in the same QLabel because I have to move the two pieces (king) together in my animations. How can I do that?
Tx a lot!!
aamer4yu
11th February 2010, 12:37
I guess graphics view framework is suitable for your need.
Have a look at QGraphicsView and QGraphicsScene and QGraphicsPixmapItem
AL
11th February 2010, 13:47
tx a lot for your help aamer4yu. I am doing as you suggested. This is the code (in progress)...
lPixmap.load("piece.png");
scene->addPixmap(lPixmap);
ui_graphicsView->setScene(scene);
ui_graphicsView->show();
ui_graphicsView->adjustSize();
By the way I still have 2 questions:
1) I noticed that the QGraphicsView is not transparent. Is it possible to apply transaprency?
2) is it possible to add a second image to the scene with a different y coordinate?
Tx
AL
11th February 2010, 13:58
hello,
just solved point 1:
ui_graphicsView->setStyleSheet("background: transparent");
still looking at point 2.... :)
AL
11th February 2010, 14:18
found the solution for the second point too!
This is the code.
QGraphicsScene *scene = new QGraphicsScene(this);
QPixmap lPixmap;
lPixmap.load("piece.png");
scene->addPixmap(lPixmap);
//add the second item
QGraphicsPixmapItem *test = scene->addPixmap(lPixmap);
//and set its offset
test->setOffset(0,-6);
ui_graphicsView->setScene(scene);
ui_graphicsView->show();
ui_graphicsView->adjustSize();
Cheers!!
aamer4yu
11th February 2010, 17:49
Am doubtful if using offset is the right way to go...
test is a QGraphicsPixmapItem and you can set its position in the scene... [QGraphicsItem::setPos]
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.