HappyEnd
HappyEnd

Reputation: 19

How to do overlapping custom items in qt?

Like in the title. I have few objects, and i wanted to set graphics to them and overlap each other. I'm setting 18 squares (terrains). I'm adding to this terrains graphics:

setPixmap(QPixmap(":Graphics/Terrain")); like so.

Then i want to add frame to it. I have 4 files of format .png, every one is 200x200px. First one is terrain.png - it's a green square, second and third are frames, about 20px wide with a transparent center (with alpha channel) and the last .png file is City.png, in left corner of City.png, there is a small graphics, rest is transparent (alpha channel). When i'm trying to set the frame by the same way as terrain.png:

setPixmap(QPixmap(":Graphics/Frame"));

it covers all of the terrain.png graphics, despite the fact that the center of frame1.png is transparent.

Furthermore i want to add some others object like for example City.png. How to do it? Mayby exists some diffrent way except using this setPixmap function ?

Upvotes: 0

Views: 218

Answers (1)

bunto1
bunto1

Reputation: 331

The setPixmap approach seems to work quite nicely, when used like this:

QGraphicsScene* scene = new QGraphicsScene();

QGraphicsPixmapItem* itemA = new QGraphicsPixmapItem();
itemA->setPixmap(QPixmap(":/NonTransparentImage.png"));
scene->addItem(itemA);

QGraphicsPixmapItem* itemB = new QGraphicsPixmapItem();
itemB->setPixmap(QPixmap(":/TransparentImage.png"));
scene->addItem(itemB);

QGraphicsView* view = new QGraphicsView(scene);
view->show();

As you expect, the transparent itemB overlaps itemA.

Upvotes: 1

Related Questions