Solved How to draw and change the region (semi-transparent) on top of a QLabel or QImage?
-
I made this class Please tell me how to set the method set2Images()?
#ifndef QLABEL2IMAGES_H #define QLABEL2IMAGES_H #include "QLabel" class QLabel2Images : public QLabel { public: QLabel2Images(); ~QLabel2Images(); void set2Images(QImage &downImage, QImage &yopImage); }; #endif // QLABEL2IMAGES_H
-
@Mikeeeeee said in How to draw and change the region (semi-transparent) on top of a QLabel or QImage?:
how to set the method
Don't understand what you mean with this sentence - how to call this function? How to implement the function - since you're writing the function you should know it by your own.
-
I don't know how to implement it. Need one figure to place from below, the second figure(transparent) to place from above.
-
When the second image is (mostly) transparent then simply paint the first and then the second.
-
The first is easy to add by setImage(), but how to add the second?
-
@Mikeeeeee said in How to draw and change the region (semi-transparent) on top of a QLabel or QImage?:
The first is easy to add by setImage(), but how to add the second?
No, you have to write it on your own by reimplementing the paintEvent()
When the second image is (mostly) transparent then simply paint the first and then the second. -
Hi
Well you already had most of the code in the first versionvirtual void paintEvent(QPaintEvent* e) { QLabel::paintEvent(e); // paint the base image QPainter p(this); p.drawQImage(0, 0, OtherQImage); // draw the other image } };
so your void set2Images(QImage &downImage, QImage &yopImage);
so set one image to the normal setPixmap for label and store the other one (the overlay) in a new variable
which you then use to draw it. ( like OtherQImage) -
Hi,
An alternative would be to compose the two images before setting the result on the QLabel.
-
@SGaist
That's actually a better idea as the base image will be scaled with a factor
so combining them first would
make the zooming easier to handle.QImage base; // set to some file/size QImage overlay; // set to some file/size QPainter paint(&base); paint.drawImage(0,0,overlay); ui->label->setPixmap(QPixmap::fromImage(base));
-
Many thanks. That's how it works:
QImage mapImage(":/Images/Images/mapMain.png"); myImageViewer->setImage(mapImage); QImage base(":/Images/Images/mapMain.png"); // set to some file/size QImage overlay(":/Images/Images/mapTop.png"); // set to some file/size QPainter paint(&base); paint.drawImage(0,0,overlay); myImageViewer->imageLabel->setPixmap(QPixmap::fromImage(base)); ui->verticalLayout->addWidget(myImageViewer);