<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Save a QPixmap in a label]]></title><description><![CDATA[<p dir="auto">Hello,</p>
<p dir="auto">I would like to save my picture (QPixmap) as a png in my label, when I finished to add lines and ellipses.<br />
Like describe in the commentaries:</p>
<p dir="auto">@<br />
//---------------------------------------------Class LabelImage<br />
class LabelImage: public QLabel<br />
{<br />
public:</p>
<pre><code>LabelImage()
{
  this-&gt;setMouseTracking(true);
};

void paintEvent (QPaintEvent *event)
{
     QLabel::paintEvent( event );
     QPainter painter(this);
         
          // LINES ANS ELLIPSES TREATMENT LOOPS

         // BACK UP HERE ! like:
         //monPixmap.save("/Users/.../Desktop/GUI Picture/Picture " + 
         //QString::number(NumberOfPicture) +".png","png",100);
                         
                MesureFinished = true;
}

void mousePressEvent (QMouseEvent * event)
{
    if (MesureFinished == false)
    {
        PixelColumn = event-&gt;x();
        PixelRow = event-&gt;y();
        this-&gt;update();
        QLabel::mousePressEvent( event );
    }
};
</code></pre>
<p dir="auto">};<br />
@</p>
]]></description><link>https://forum.qt.io/topic/36647/save-a-qpixmap-in-a-label</link><generator>RSS for Node</generator><lastBuildDate>Sun, 02 Aug 2026 00:59:27 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/36647.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 15 Jan 2014 15:12:39 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Save a QPixmap in a label on Mon, 27 Jan 2014 15:39:17 GMT]]></title><description><![CDATA[<p dir="auto">Ok I will check. Thank you</p>
]]></description><link>https://forum.qt.io/post/212429</link><guid isPermaLink="true">https://forum.qt.io/post/212429</guid><dc:creator><![CDATA[MélissaQT]]></dc:creator><pubDate>Mon, 27 Jan 2014 15:39:17 GMT</pubDate></item><item><title><![CDATA[Reply to Save a QPixmap in a label on Mon, 27 Jan 2014 14:54:21 GMT]]></title><description><![CDATA[<p dir="auto">Then have a look at the Qt's Plug And Paint example,  that will provide you a good ground to build on</p>
]]></description><link>https://forum.qt.io/post/212417</link><guid isPermaLink="true">https://forum.qt.io/post/212417</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Mon, 27 Jan 2014 14:54:21 GMT</pubDate></item><item><title><![CDATA[Reply to Save a QPixmap in a label on Mon, 27 Jan 2014 14:31:51 GMT]]></title><description><![CDATA[<p dir="auto">Hi SGaist,</p>
<p dir="auto">Yes something like that</p>
]]></description><link>https://forum.qt.io/post/212413</link><guid isPermaLink="true">https://forum.qt.io/post/212413</guid><dc:creator><![CDATA[MélissaQT]]></dc:creator><pubDate>Mon, 27 Jan 2014 14:31:51 GMT</pubDate></item><item><title><![CDATA[Reply to Save a QPixmap in a label on Thu, 16 Jan 2014 21:14:39 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">Are you trying to create something like a Paint program ?</p>
]]></description><link>https://forum.qt.io/post/211113</link><guid isPermaLink="true">https://forum.qt.io/post/211113</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Thu, 16 Jan 2014 21:14:39 GMT</pubDate></item><item><title><![CDATA[Reply to Save a QPixmap in a label on Thu, 16 Jan 2014 09:48:13 GMT]]></title><description><![CDATA[<p dir="auto">Thanks all for those answers,</p>
<p dir="auto">[quote author="Dheerendra" date="1389809506"]I'm assuming that you have picture in png format. You need to load this in pixmap and set this to label. Is that correct ?</p>
<ol>
<li>Load the your png file to PixMap</li>
<li>Set this PixMap to QLabel</li>
</ol>
<p dir="auto">Subclassing QLabel and implementing paintEvent will re-draw you label.</p>
<p dir="auto">[/quote]</p>
<p dir="auto">I now back up the picture without figures (circles and ellipses) with this code:</p>
<p dir="auto">@</p>
<p dir="auto">//---------------------------------------------Class LabelImage<br />
class LabelImage: public QLabel<br />
{<br />
QPixmap mypix; //----------------------------------------------------NEW<br />
public:</p>
<pre><code>LabelImage()
{
  mypix = ("..."); //---------------------NEW
  this-&gt;setPixmap(mypix);//---------------------NEW

  this-&gt;setMouseTracking(true);
};

void paintEvent (QPaintEvent *event)
{
     QLabel::paintEvent( event );
     QPainter painter(this);
         
          // LINES ANS ELLIPSES TREATMENT LOOPS
                         
                MesureFinished = true;
                mypix.save(".."); //--------------------------------------NEW
}

void mousePressEvent (QMouseEvent * event)
{
    if (MesureFinished == false)
    {
        PixelColumn = event-&gt;x();
        PixelRow = event-&gt;y();
        this-&gt;update();
        QLabel::mousePressEvent( event );
    }
};
</code></pre>
<p dir="auto">};<br />
@</p>
<p dir="auto">How I can save picture + figures?</p>
]]></description><link>https://forum.qt.io/post/211042</link><guid isPermaLink="true">https://forum.qt.io/post/211042</guid><dc:creator><![CDATA[MélissaQT]]></dc:creator><pubDate>Thu, 16 Jan 2014 09:48:13 GMT</pubDate></item><item><title><![CDATA[Reply to Save a QPixmap in a label on Thu, 16 Jan 2014 06:40:00 GMT]]></title><description><![CDATA[<p dir="auto">Try this..<br />
QString format = "png";</p>
<pre><code>QString fileName=CurrentDirPath+"/"+"image.png"; 

QPixmap originalPixmap; 

originalPixmap=QPixmap::grabWidget(label);


if (!fileName.isEmpty())

    originalPixmap.save(fileName, format.toAscii());
</code></pre>
]]></description><link>https://forum.qt.io/post/211014</link><guid isPermaLink="true">https://forum.qt.io/post/211014</guid><dc:creator><![CDATA[IamSumit]]></dc:creator><pubDate>Thu, 16 Jan 2014 06:40:00 GMT</pubDate></item><item><title><![CDATA[Reply to Save a QPixmap in a label on Wed, 15 Jan 2014 18:11:46 GMT]]></title><description><![CDATA[<p dir="auto">I'm assuming that you have picture in png format. You need to load this in pixmap and set this to label. Is that correct ?</p>
<ol>
<li>Load the your png file to PixMap</li>
<li>Set this PixMap to QLabel</li>
</ol>
<p dir="auto">Subclassing QLabel and implementing paintEvent will re-draw you label.</p>
]]></description><link>https://forum.qt.io/post/210957</link><guid isPermaLink="true">https://forum.qt.io/post/210957</guid><dc:creator><![CDATA[dheerendra]]></dc:creator><pubDate>Wed, 15 Jan 2014 18:11:46 GMT</pubDate></item><item><title><![CDATA[Reply to Save a QPixmap in a label on Wed, 15 Jan 2014 15:40:36 GMT]]></title><description><![CDATA[<p dir="auto">No way to go. You have to draw in a QPixmap instead by doing something like:<br />
@QPainter p(pixmap);@<br />
Don't do it inside paintEvent.</p>
<p dir="auto">Then you can save the pixmap and display it in a QWidget inside paintEvent using painter.drawPixmap(). No need to subclass QLabel, just subclass QWidget.</p>
]]></description><link>https://forum.qt.io/post/210945</link><guid isPermaLink="true">https://forum.qt.io/post/210945</guid><dc:creator><![CDATA[flaviotordini]]></dc:creator><pubDate>Wed, 15 Jan 2014 15:40:36 GMT</pubDate></item><item><title><![CDATA[Reply to Save a QPixmap in a label on Wed, 15 Jan 2014 15:17:07 GMT]]></title><description><![CDATA[<p dir="auto">and here the c++ code where I'm using the .h:<br />
@<br />
//---------------------------------------------PICTURE WINDOW<br />
PictureWindow::PictureWindow(QImage Image, int NumberOfPicture) : QWidget()<br />
{<br />
setFixedSize(840, 356);</p>
<pre><code>QPixmap monPixmap;

LabelImage* LabelIMG = new LabelImage();

LabelIMG-&gt; setFixedSize(monPixmap.fromImage(Image).size());
</code></pre>
<p dir="auto">}<br />
@</p>
]]></description><link>https://forum.qt.io/post/210946</link><guid isPermaLink="true">https://forum.qt.io/post/210946</guid><dc:creator><![CDATA[MélissaQT]]></dc:creator><pubDate>Wed, 15 Jan 2014 15:17:07 GMT</pubDate></item></channel></rss>