Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to add a logo in a specific size?
Forum Updated to NodeBB v4.3 + New Features

How to add a logo in a specific size?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 395 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • eefesafakE Offline
    eefesafakE Offline
    eefesafak
    wrote on last edited by eefesafak
    #1

    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);
        }
    

    Screenshot from 2022-06-13 10-44-59.png
    Screenshot from 2022-06-13 10-45-02.png

    eefesafakE 1 Reply Last reply
    0
    • eefesafakE eefesafak

      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);
          }
      

      Screenshot from 2022-06-13 10-44-59.png
      Screenshot from 2022-06-13 10-45-02.png

      eefesafakE Offline
      eefesafakE Offline
      eefesafak
      wrote on last edited by
      #2

      @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.

      J.HilkJ 1 Reply Last reply
      0
      • eefesafakE eefesafak

        @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.

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #3

        @eefesafak please solve this as well

        QThread::msleep(2000);

        it hurts my soul.


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        eefesafakE 1 Reply Last reply
        0
        • J.HilkJ J.Hilk

          @eefesafak please solve this as well

          QThread::msleep(2000);

          it hurts my soul.

          eefesafakE Offline
          eefesafakE Offline
          eefesafak
          wrote on last edited by
          #4

          @J-Hilk Why does it hurt your soul? I used it to see result better. Normally, it's not inside the code. What can i use instead?

          J.HilkJ 1 Reply Last reply
          0
          • eefesafakE eefesafak

            @J-Hilk Why does it hurt your soul? I used it to see result better. Normally, it's not inside the code. What can i use instead?

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            @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;
                });
            

            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            2

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved