13 {
14 init();
15 }
16
17 void MyWidget :: init()
18 {
19 QImage bg
( width
(), height
(),
QImage::Format_ARGB32_Premultiplied );
20 QImage a
( width
(), height
(),
QImage::Format_ARGB32_Premultiplied );
21 QImage b
( width
(), height
(),
QImage::Format_ARGB32_Premultiplied );
22
24
25 p.begin( &bg );
27 p.fillRect( r, Qt::white );
28 p.end();
29
30 p.begin( &a );
32 p.drawLine( 10, 10, 50, 50 );
33 p.end();
34
35 p.begin( &b );
37 p.drawLine( 10, 70, 50, 10 );
38 p.end();
39
40 p.begin( this );
41 p.
drawImage( QPoint(0,
0), bg
);
42 p.
drawImage( QPoint(0,
0), a
);
43 p.
drawImage( QPoint(0,
0), b
);
44 p.end();
45 }
12 void MyWidget :: paintEvent ( QPaintEvent * event )
13 {
14 init();
15 }
16
17 void MyWidget :: init()
18 {
19 QImage bg( width(), height(), QImage::Format_ARGB32_Premultiplied );
20 QImage a( width(), height(), QImage::Format_ARGB32_Premultiplied );
21 QImage b( width(), height(), QImage::Format_ARGB32_Premultiplied );
22
23 QPainter p;
24
25 p.begin( &bg );
26 QRect r = rect();
27 p.fillRect( r, Qt::white );
28 p.end();
29
30 p.begin( &a );
31 p.setPen( QPen( QColor( Qt::red ), 5 ) );
32 p.drawLine( 10, 10, 50, 50 );
33 p.end();
34
35 p.begin( &b );
36 p.setPen( QPen( QColor( Qt::green ), 5 ) );
37 p.drawLine( 10, 70, 50, 10 );
38 p.end();
39
40 p.begin( this );
41 p.drawImage( QPoint(0,0), bg );
42 p.drawImage( QPoint(0,0), a );
43 p.drawImage( QPoint(0,0), b );
44 p.end();
45 }
To copy to clipboard, switch view to plain text mode
Bookmarks