4 //use this rectangle in source image
5 const int src_xoff = 15;
6 const int src_yoff = 23;
7 const int src_width = 600;
8 const int src_height = 500;
9 const QRect src_rect(src_xoff, src_yoff, src_width, src_height);
12 class Widget : public QWidget {
17 msecs = paints = mode = 0;
18 img = QImage("stripes.png");
20 QTimer *timer = new QTimer(this);
21 connect(timer, SIGNAL(timeout()),
22 this, SLOT(repaint()));
27 virtual void paintEvent(QPaintEvent*);
30 int msecs, paints, mode;
33 void Widget::paintEvent(QPaintEvent*)
35 QPainter painter(this);
36 //painter.setRenderHint(QPainter::SmoothPixmapTransform);
42 //scaled (fit to window)
43 case 0: //this is how small updates in 0.6 are done
44 painter.drawImage(rect(),
46 .scaled(size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
48 case 1: //fast transformation
49 painter.drawImage(rect(),
51 .scaled(size(), Qt::IgnoreAspectRatio, Qt::FastTransformation));
53 case 2: //tell drawImage() that no further scaling is required
54 //why different from 1?
55 painter.drawImage(rect().topLeft(),
57 .scaled(size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
59 case 3: //avoid scaled()
60 painter.drawImage(rect(),
63 case 4: //avoid copy() and scaled()
64 painter.drawImage(rect(), img, src_rect);
67 // not scaled - repeat preceeding tests with dimensions that just happen to require no transformation
68 // these are all comparable
69 case 5: //this is how small updates in 0.6 are done
70 painter.drawImage(rect(),
72 .scaled(size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
74 case 6: //fast transformation
75 painter.drawImage(rect(),
77 .scaled(size(), Qt::IgnoreAspectRatio, Qt::FastTransformation));
79 case 7: //tell drawImage() that no further scaling is required
80 painter.drawImage(rect().topLeft(),
82 .scaled(size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
84 case 8: //avoid scaled()
85 painter.drawImage(rect(),
88 case 9: //avoid copy() and scaled()
89 painter.drawImage(rect(), img, rect());
93 painter.drawImage(rect().topLeft(), img, rect());
96 painter.drawImage(rect().topLeft(), img);
99 painter.drawImage(rect().topLeft(),
102 case 13: //5 with KeepAspectRatio
103 painter.drawImage(rect(),
105 .scaled(size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
109 msecs += t.elapsed();
112 const int paints_per_mode = 20;
113 const int num_modes = 14;
115 if(paints > paints_per_mode) {
116 std::cout << mode << ":\t" << double(msecs)/paints << " msecs per paint\n";
119 if(mode >= num_modes)
125 int main(int argc, char* argv[])
127 QApplication app(argc, argv);