How to add a logo in a specific size?
Solved
General and Desktop
-
Hi everyone, My goal is to add a logo on QImage. However, when the every QImage changes, the size of logo is changing concurrently. How can i prevent this? Thanks for your precious time. Here is my code and example:
foreach(const QString& string, m_fileList) { QImage image(string); QString logoPath = "/home/efe/Desktop/logo.png"; QImage logo(logoPath); QImage logo2 = logo.scaled(100, 100, Qt::KeepAspectRatio); QPainter painter(&image); painter.setOpacity(0.5); const QPoint point(10, 10); painter.drawImage(point, logo2); painter.end(); ui->imageLabel->setPixmap(QPixmap::fromImage(image)); QThread::msleep(2000); }
-
@eefesafak I just understood what's going on. I had
ui->imageLabel->setScaledContents(true);
in my constructor. Actually, the size of logo was not changed. I change my code to :
ui->imageLabel->setScaledContents(false);
and my problem was solved.
-
-
@eefesafak you're lucky, that you see something painted at all.
use a QTimer!
here a quick and dirty implementation ;) :
QTimer *t(new QTimer()); QObject::connect(t, &QTimer::timeout, [=](int index = 0) mutable ->void{ if(index >= m_fileList.size()){ t->deleteLater(); return; } QImage image(m_fileList.at(index)); QString logoPath = "/home/efe/Desktop/logo.png"; QImage logo(logoPath); QImage logo2 = logo.scaled(100, 100, Qt::KeepAspectRatio); QPainter painter(&image); painter.setOpacity(0.5); const QPoint point(10, 10); painter.drawImage(point, logo2); painter.end(); ui->imageLabel->setPixmap(QPixmap::fromImage(image)); ++index; });