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. Insert image on other QImage in QLabel
Forum Updated to NodeBB v4.3 + New Features

Insert image on other QImage in QLabel

Scheduled Pinned Locked Moved Solved General and Desktop
qlabelqimage
8 Posts 3 Posters 12.1k Views 2 Watching
  • 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 Offline
    K Offline
    kevin32
    wrote on last edited by A Former User
    #1

    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
    0
    • K kevin32

      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

      ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

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

      K 1 Reply Last reply
      1
      • ? A Former User

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

        K Offline
        K Offline
        kevin32
        wrote on last edited by
        #3

        @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
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

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

          K 1 Reply Last reply
          1
          • ? A Former User

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

            K Offline
            K Offline
            kevin32
            wrote on last edited by
            #5

            @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
            0
            • K kevin32

              @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.
              ? Offline
              ? Offline
              A Former User
              wrote on last edited by A Former User
              #6

              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
              1
              • K Offline
                K Offline
                kevin32
                wrote on last edited by
                #7

                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
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  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
                  0

                  • Login

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