Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Insert image on other QImage in QLabel

    General and Desktop
    qlabel qimage
    3
    8
    10748
    Loading More Posts
    • 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.
    • K
      kevin32 last edited by A Former User

      Hi everyone, can you help me please?

      I would like display qimage on other qimage in qlabel, but i want to size of qimage not resize in qlabel, and insert qimage in special coords of qlabel example top or bot.

      thanks for helping

      ? 1 Reply Last reply Reply Quote 0
      • ?
        A Former User @kevin32 last edited by

        @kevin32 Hi! You could create a custom widget, derived from QWidget, and place two QLabels on it.

        K 1 Reply Last reply Reply Quote 1
        • K
          kevin32 @Guest last edited by

          @Wieland thanks, i display my image like that

           // create Qpixmap from Qimage
              QPixmap pix = QPixmap::fromImage(img);
              // display the pixmap on the label
              ui->label->setPixmap(pix);
          

          it's ok, my label and qimage is already in custom widget but, how to insert special coords its possible with setpixamp?

          example:
          my label : width 800 height 800
          my first qimage : width 800 height 800
          my second qimage insert dynamically with code : x: 0 , y 50 i would like change coords and size.

          http://img11.hostingpics.net/pics/581570example.png

          Thanks for you helping :)

          1 Reply Last reply Reply Quote 0
          • ?
            A Former User last edited by

            Changing position and size can be done with void QWidget::setGeometry(int x, int y, int w, int h).

            K 1 Reply Last reply Reply Quote 1
            • K
              kevin32 @Guest last edited by

              @Wieland thanks you very much ```
              QPixmap px("C://Users//user//Pictures//a.png");
              ui->label->setPixmap(px);
              ui->label->setGeometry(0,0,100,100);
              if(!px.isNull())
              {
              ui->label->setPixmap(px);
              ui->label->show();
              }

              
              Sorry but finally how to resize image for exemple here image of 200:200 display in 100:100 thanks you.
              ? 1 Reply Last reply Reply Quote 0
              • ?
                A Former User @kevin32 last edited by A Former User

                You can resize the pixmap before handing it to the label with on of QPixmap's scaled() methods, e.g. QPixmap QPixmap::scaled(const QSize &size, Qt::AspectRatioMode aspectRatioMode = Qt::IgnoreAspectRatio, Qt::TransformationMode transformMode = Qt::FastTransformation) const

                QPixmap px("C://Users//user//Pictures//a.png");
                px = px.scaled( QSize(100,100) );
                ui->label->setPixmap(px);
                
                1 Reply Last reply Reply Quote 1
                • K
                  kevin32 last edited by

                  I find other method with ```
                  QPixmap *pixmap=new QPixmap(ui->label->width(), ui->label->height());
                  QPainter *painter=new QPainter(pixmap);
                  painter->drawPixmap(100, 0, 50, 50, QPixmap("C://Users//user//Pictures//a.png"));
                  painter->drawPixmap(0, 0, 100, 100, QPixmap("C://Users//user//Pictures//1.png"));
                  painter->end();
                  ui->label->setPixmap(*pixmap);

                  
                  ithank you for helping
                  1 Reply Last reply Reply Quote 0
                  • SGaist
                    SGaist Lifetime Qt Champion last edited by

                    Hi,

                    You have two memory leaks now. There's no need to allocate pixmap nor painter on the heap.

                    i.e:

                    QPixmap pixmap(ui->label->width(), ui->label->height());
                    QPainter painter=(&pixmap);
                    painter.drawPixmap(100, 0, 50, 50, QPixmap("C:/Users/user/Pictures/a.png"));
                    painter.drawPixmap(0, 0, 100, 100, QPixmap("C:/Users/user/Pictures/1.png"));
                    painter.end();
                    ui->label->setPixmap(pixmap);
                    

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post