[Qt-interest] Drawing to QImage

Denis Akhmetzyanov dakhmetzyanov at smartlabs.tv
Fri Apr 16 11:22:53 CEST 2010


Hi, Alex
BRM wrote:

> I'm looking for some good information on drawing to QImage *instead of
directly in a QWidget*.

So I think about case when we paint on QImage, then paint QImage on QWidget
("indirect" drawing). Not about simple painting on QImage and writing QImage
to file. Something like this:

void MyWidget::paintEvent(QPaintEvent *) {
     QImage bufferImage( size() );
     QPainter imagePainter(&bufferImage);

     // draw widget's content on imagePainter
     ...

     imagePainter.end();
     QPainter widgetPainter(this);
     widgetPainter.drawImage(0, 0, bufferImage);
}

I've used this approach for some embedded devices. Qt documentation and
aforementioned book recommends using QImage for this purpose because it is
hardware independent. Yes, QPixmap is optimized for showing images on
screen, but it may be hardware dependent.


2010/4/16 Malyushytsky, Alex <alex at wai.com>

>  According to my understanding main reason to draw on QImage is to perform
> drawing when you don’t have device to draw on.
>
> It does not require QApplication ( QWidgets , etc. ) and for example can be
> done from applications  which don’t have GUI at all.
>
> In the most other cases you would prefer to draw on pixmap and convert to
> QImage only when you need to save drawing to the file.
>
>
>
> Performance in general should be better when you draw on QPixmap .
>
>
>
> Regards,
>
>       Alex
>
>
>
>
>
>
>
> *From:* qt-interest-bounces at trolltech.com [mailto:
> qt-interest-bounces at trolltech.com] *On Behalf Of *Denis Akhmetzyanov
> *Sent:* Thursday, April 15, 2010 1:31 AM
> *To:* BRM
> *Cc:* qt-interest
> *Subject:* Re: [Qt-interest] Drawing to QImage
>
>
>
> Hi,
>
> *C++ GUI Programming with Qt 4 (2nd Edition) - The official C++/Qt book*
>
> *
> http://qt.nokia.com/developer/books/cpp-gui-programming-with-qt-4-2nd-edition
>  *
>
>
>
> has some useful information about this question. Part  II, Chapter 8, 2D
> Graphics, topic "High-Quality Rendering with QImage".
>
> In my experience, the main advantage of drawing on the QImage is that
> rendering result looking exactly the same on all platforms. But performance
> is worse than direct drawing on a QWidget.
>
>
>
>
>
> 2010/4/14 BRM <bm_witness at yahoo.com>
>
> I'm looking for some good information on drawing to QImage instead of
> directly in a QWidget.
> Doing a quick google search didn't up much useful information; and while
> I've taken my first stab at it - my results were not useful either.
> I know I'm probably doing something wrong; and would like to be able to
> read over some stuff on it; but the Qt documentation merely mentions it in
> passing.
>
> TIA,
>
> Ben
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
>
>
> --
> Best regards,
> Denis Akhmetzyanov
>
>
>
> ---------------------------------------------------------------------------------------------------
> Weidlinger Associates, Inc. made the following annotations.
>
> “This message and any attachments are solely for the intended recipient and
> may contain confidential or privileged information. If you are not the
> intended recipient, any disclosure, copying, use, or distribution of the
> information included in this message and any attachments is prohibited. If
> you have received this communication in error, please notify us by reply
> e-mail and immediately and permanently delete this message and any
> attachments. Thank you.”
>
> “Please consider our environment before printing this email.”
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>


-- 
Best regards,
Denis Akhmetzyanov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100416/febea817/attachment.html 


More information about the Qt-interest-old mailing list