Trouble with image painting (QPainter + QImage)
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
Re: Trouble with image painting (QPainter + QImage)
Quote:
Originally Posted by krivenok
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:
Quote:
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.