Routine: // method of the rectangle 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::paintEvent(QPaintEvent *)
// The paintevent function is automatically called by the system and does not need to be manually called. { Paint = new qpainter; Paint-> begin (this ); Paint-> setpen (qpen (QT: blue, 4, QT: dashline); // you can specify a paint brush. Paint-> setbrush (qbrush (QT: Red, QT: solidpattern); // you can specify a paint brush. 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 result: the Core code of the circle and ellipse is: paint-> setpen (qpen (QT: blue, 4, QT: solidline); paint-> drawellipse (20, 20, 210,160 ); the first, second, and second parameters respectively indicate the number of degrees between the circle and the elliptic distance from the upper left corner. The 3 or 4 parameters indicate the width and height of the circle/elliptic. More accurately, the circle or elliptic is in the rectangle, and the vertex in the upper left corner of the rectangle is in the coordinate axis ), the center of the circle or oval is the center of the rectangle. The following are similar !!! Core code for drawing a rounded rectangle: paint-> setpen (qpen (QT: blue, 4, QT: solidline); paint-> drawroundrect (20, 20, 210,160, 50, 50 ); the last two parameters determine the width of the angle. It can be any value between 0 and 99 (99 represents the circle ). Core code for creating a sector chart: paint-> setpen (qpen (QT: Green, 4, QT: solidline); paint-> drawpie (20, 20, 210,160, 0,500 ); the first four Parameter definition circles (same as the drawellipse () function ). The last two parameters define the circle style. 0 is the starting angle (the actual unit is 1/16 degrees), and 500 is the angle of the slice (The unit is also 1/16 degrees ). Core code for drawing a string: paint-> setpen (qpen (QT: Green, 4, QT: solidline); paint-> drawchord (20, 20, 210,160,500,100 0); drawchord () the parameters of the function and the drawpie () function are identical. Core code for drawing an arc: paint-> setpen (qpen (QT: Green, 4, QT: solidline); paint-> drawarc (20, 20, 210,160,500,100 0); drawarc () the parameters of the function and the drawpie () function are identical. Core code for drawing the besell curve: paint-> setpen (qpen (QT: Green, 4, QT: solidline); paint-> drawquadbeier (qpointarray (qrect (20, 20, 20, (210,160); the only parameter passed to this function represents a rectangle, in which the besell curve is created (other parameters are default parameters, which can be omitted ). |