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("test.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);
41 //scaled (fit to window)
42 case 0: //this is how small updates in 0.6 are done
43 painter.drawImage(rect(),
45 .scaled(size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
47 case 1: //fast transformation
48 painter.drawImage(rect(),
50 .scaled(size(), Qt::IgnoreAspectRatio, Qt::FastTransformation));
52 case 2: //tell drawImage() that no further scaling is required
53 //why different from 1?
54 painter.drawImage(rect().topLeft(),
56 .scaled(size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
58 case 3: //avoid scaled()
59 painter.drawImage(rect(),
62 case 4: //avoid copy() and scaled()
63 painter.drawImage(rect(), img, src_rect);
66 // not scaled - repeat preceeding tests with dimensions that just happen to require no transformation
67 // these are all comparable
68 case 5: //this is how small updates in 0.6 are done
69 painter.drawImage(rect(),
71 .scaled(size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
73 case 6: //fast transformation
74 painter.drawImage(rect(),
76 .scaled(size(), Qt::IgnoreAspectRatio, Qt::FastTransformation));
78 case 7: //tell drawImage() that no further scaling is required
79 painter.drawImage(rect().topLeft(),
81 .scaled(size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
83 case 8: //avoid scaled()
84 painter.drawImage(rect(),
87 case 9: //avoid copy() and scaled()
88 painter.drawImage(rect(), img, rect());
92 painter.drawImage(rect().topLeft(), img, rect());
95 painter.drawImage(rect().topLeft(), img);
98 painter.drawImage(rect().topLeft(),
101 case 13: //5 with KeepAspectRatio
102 painter.drawImage(rect(),
104 .scaled(size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
108 msecs += t.elapsed();
111 const int paints_per_mode = 20;
112 const int num_modes = 14;
114 if(paints > paints_per_mode) {
115 std::cout << mode << ":\t" << double(msecs)/paints << " msecs per paint\n";
118 if(mode >= num_modes)
124 int main(int argc, char* argv[])
126 QApplication app(argc, argv);