PDA

View Full Version : Trouble with image painting (QPainter + QImage)



krivenok
4th February 2006, 21:14
Hello!

Why this code is incorrect?
Why image doesn't painting in frame?

//////////////////////////////////////////////////////////////////
#include <QtGui>
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QFrame f;
QPainter p(&f);
QImage i("tst.jpg");
p.drawImage(0,0,i);
f.show();
return app.exec();
}
//////////////////////////////////////////////////////////////////

P.S.
mingw / QT-4.1.0

jacek
4th February 2006, 21:25
Why this code is incorrect?
Why image doesn't painting in frame?

Everything you draw on a hidden widget will be discarded.
Make sure you have JPEG image format plugin compiled
The docs say:
Warning: Unless a widget has the Qt::WA_PaintOutsidePaintEvent attribute set. A QPainter can only be used on a widget inside a paintEvent() or a function called by a paintEvent(). On Mac OS X, you can only paint on a widget in a paintEvent() regardless of this attribute's setting.

If you want to show an image, use QLabel and the QLabel::setPixmap() method.