Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED]How to add an icon(image) to QImage and update the image
Qt 6.12 LTS is out! See what's new in the release blog

[SOLVED]How to add an icon(image) to QImage and update the image

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 4.4k Views 1 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Think that; I have a button, it creates a QImage and display it in a QLabel.
    @QRgb value;
    myImage = new QImage(col, row, QImage::Format_RGB32);

    for( int i = 0; i < row; i++ )
    {
    for( int j = 0; j < col; j++ )
    {
    value = qRgb(myData[i][j].intensity *.3,myData[i][j].intensity *.59,myData[i][j].intensity *.11);
    myImage->setPixel(j,i,value);
    }
    }
    imageLabel->setPixmap(QPixmap::fromImage(*myImage));
    @
    Now I add another button and it must add an icon to the QImage and update the displayed image.
    @ QPixmap p("abc.png");
    QPixmap pixmap = QPixmap::fromImage(*myImage);
    QPainter painter(&pixmap);
    painter.drawPixmap(100,100, p);
    @
    I did like this, the program executes the code but does not display the icon.
    How can I fix it?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      You have only painted to the pixmap, but you need to set the pixmap to the label you want to show it on (even if it has been set on it before).

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        You are right, thanks

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          -Please mark the topic as [Solved] by editing the title of the topic from your first post.-

          Edit: You already did. Thanks :-)

          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
          • Unsolved