I'm suprised you see anything at all apart the white background.
This is the correct code:
#include <QtGui>
public:
img.fill(0);
for(int n = 0; n < 500; ++n)
for(int i = 0; i< 500; ++i)
img.setPixel(i, n, qRgb(255,0,255));
setAutoFillBackground(true);
}
protected:
painter.drawImage(img.rect(), img);
}
private:
};
int main(int argc, char **argv) {
Widget w;
w.show();
return app.exec();
}
#include <QtGui>
class Widget : public QWidget {
public:
Widget() : QWidget() {
img = QImage(500,500, QImage::Format_ARGB32_Premultiplied);
img.fill(0);
for(int n = 0; n < 500; ++n)
for(int i = 0; i< 500; ++i)
img.setPixel(i, n, qRgb(255,0,255));
setBackgroundRole(QPalette::Base);
setAutoFillBackground(true);
}
protected:
void paintEvent(QPaintEvent *) {
QPainter painter(this);
painter.drawImage(img.rect(), img);
}
private:
QImage img;
};
int main(int argc, char **argv) {
QApplication app(argc, argv);
Widget w;
w.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
As for the rest of your question --- "it depends".
Bookmarks