0% found this document useful (0 votes)
48 views2 pages

Qt Graphics Shapes Drawing Code

The document defines functions for drawing different shapes using a QPainter object. The paintEvent function checks the mode variable and calls the appropriate drawing function to render a circle, square, both or a more complex shape. Separate functions are defined for drawing a circle, square, circle with arcs and a house polygon. Each function sets the pen color and draws the shape by calculating coordinates and passing them to the QPainter draw methods.

Uploaded by

NguyenHoangMinh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views2 pages

Qt Graphics Shapes Drawing Code

The document defines functions for drawing different shapes using a QPainter object. The paintEvent function checks the mode variable and calls the appropriate drawing function to render a circle, square, both or a more complex shape. Separate functions are defined for drawing a circle, square, circle with arcs and a house polygon. Each function sets the pen color and draws the shape by calculating coordinates and passing them to the QPainter draw methods.

Uploaded by

NguyenHoangMinh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

void graphics::paintEvent(QPaintEvent *)

{
QPainter painter(this);
if(mode == 2) HinhTron(painter);
if(mode == 3) HinhVuong(painter);
if(mode == 4) {HinhTron(painter); HinhVuong(painter);}
if(mode == 5) HinhTC(painter);
if(mode == 6) Venha(painter);
}
void graphics::HinhTron(QPainter& painter)
{
painter.setPen(Qt::green);
int w,h;
w=width();
h=height();
QPoint A(w/2,h/2);
painter.drawEllipse(A,100,100);

}
void graphics::HinhVuong(QPainter& painter)
{
painter.setPen(Qt::blue);
int w,h;
float x,y;
w=width();
h=height();
x=w/2-50*sqrt(2);
y=h/2-50*sqrt(2);
painter.drawRect(x,y,200/sqrt(2),200/sqrt(2));
}
void graphics::HinhTC(QPainter& painter)
{
painter.setPen(Qt::red);
int w,h;
w=width();
h=height();
QPoint A(w/2,h/2);
painter.drawEllipse(A,100,100);
QPoint B(w/2+50,h/2);
QPoint C(w/2-50,h/2);
painter.drawEllipse(B,10,10);
painter.drawEllipse(C,10,10);
painter.drawArc(w/2-100,h/2-50,100,100,0,-180*16);
painter.drawArc(w/2,h/2-50,100,100,0,180*16);
}
void graphics::Venha(QPainter& painter)
{
painter.setPen(Qt::blue);
int w,h;
w=width();
h=height();
QPolygon nha;
nha<<QPoint(100,200)<<QPoint(200,200)<<QPoint(200,100)<<QPoint(150,50)<<QPoint(1
00,100);
painter.drawPolygon(nha);
QPolygon cuachinh;
cuachinh<<QPoint(125,200)<<QPoint(125,160)<<QPoint(150,160)<<QPoint(150,200);
painter.drawPolyline(cuachinh);
QPolygon cuaso;

cuaso<<QPoint(160,140)<<QPoint(180,140)<<QPoint(180,120)<<QPoint(160,120);
painter.drawPolygon(cuaso);
QPolygon ongkhoi;
ongkhoi<<QPoint(110,90)<<QPoint(110,50)<<QPoint(120,50)<<QPoint(120,80);
painter.drawPolyline(ongkhoi);

You might also like