Routines: Drawing of rectangles in//qt4
| #include <QApplication> #include <QWidget> #include <QPainter> Class Mymainwindow:public qwidget { Public: mymainwindow (Qwidget *parent = 0); private: void paintevent (qpaintevent *); qpainter *paint; }; void Mymainwindow::p aintevent (qpaintevent *) The//paintevent function is automatically called by the system, without the need for us to call it artificially. { paint=new qpainter; paint->begin (this); paint->setpen (Qpen (qt::blue,4,qt::D ashline));//Set brush form paint->setbrush (QBrush (Qt :: Red,qt::solidpattern)); Set the brush form paint->drawrect (20,20,160,160); paint->end (); } Mymainwindow::mymainwindow (qwidget *parent): Qwidget (parent) { setgeometry ( 100,100,200,200); } int main (int argc,char **argv) { qapplication a (ARGC,ARGV); mymainwindow W; w.show (); return a.exec (); } |
Output: Draw circle and Oval core code: Paint->setpen (Qpen (qt::blue,4,qt::solidline)); Paint->drawellipse (20,20,210,160); 1th, the 2 parameters represent the number of pixels in the upper-left corner of the circle/ellipse distance, respectively. 3rd, 4 parameters represent the width and height of a circle/ellipse. More precisely, the circle or ellipse is in the rectangle, and the vertex of the upper-left corner of the rectangle is in the axis position (20,20), the center of the circle or ellipse is the center of the rectangle, the following are similar ... Draw Rounded Rectangle Core code: Paint->setpen (Qpen (qt::blue,4,qt::solidline)); Paint->drawroundrect (20,20,210,160,50,50); The last two parameters determine the roundness of the corners. It can be any value between 0 and 99 (99 represents the most rounded). Draw the pie chart core code: Paint->setpen (Qpen (qt::green,4,qt::solidline)); Paint->drawpie (20,20,210,160,0,500); The first four parameters define a circle (same as the DrawEllipse () function). The latter two parameters define the style of the circle. 0 is the starting angle (the actual unit is 1/16 degrees), and 500 is the angle (in units of 1/16 degrees) that the sector expands. Draw chord Core code: Paint->setpen (Qpen (qt::green,4,qt::solidline)); Paint->drawchord (20,20,210,160,500,1000); The Drawchord () function is exactly the same as the parameter of the Drawpie () function. Draw Arc Core code: Paint->setpen (Qpen (qt::green,4,qt::solidline)); Paint->drawarc (20,20,210,160,500,1000); The DrawArc () function is exactly the same as the parameter of the Drawpie () function. Draw the Bézier curve Core code: Paint->setpen (Qpen (qt::green,4,qt::solidline)); Paint->drawquadbezier (Qpointarray (Qrect (20,20,210,160))); The only parameter passed to the function represents a rectangle in which the Bezier curve is created (the other parameter is the default parameter, which can be omitted). |
|
|