【如果用qt建造一个直角坐标系然后再坐标系中作图】
如果用qt建造一个直角坐标系然后再坐标系中作图
【如果用qt建造一个直角坐标系然后再坐标系中作图】
如果用qt建造一个直角坐标系然后再坐标系中作图
新建工程基类是QWidget
zuobiaozhou.h
#ifndefZUOBIAOZHOU_H
#defineZUOBIAOZHOU_H
#include
classzuobiaozhou:publicQWidget
{
Q_OBJECT
public:
zuobiaozhou(QWidget*parent=0);
zuobiaozhou();
protected:
voidpaintEvent(QPaintEvent*);
};
#endif//ZUOBIAOZHOU_H
main.cpp
#include
#include"zuobiaozhou.h"
intmain(intargc,char*argv[])
{
QApplicationa(argc,argv);
zuobiaozhouw;
w.showMaximized();//窗口默认最大化
returna.exec();
}
zuobiaozhou.cpp
#include"zuobiaozhou.h"
zuobiaozhou::zuobiaozhou(QWidget*parent)
:QWidget(parent)
{
setWindowTitle(tr("zuobiaozhou"));//设置标题栏标题
resize(400,300);//设置窗口初始大小
}
zuobiaozhou::zuobiaozhou()
{
}
voidzuobiaozhou::paintEvent(QPaintEvent*)
{
intside=qMin(width(),height());//创建窗口宽高参数
QPainterpainter(this);
painter.setRenderHint(QPainter::Antialiasing,true);//开启抗锯齿
painter.translate(width()/2,height()/2);//坐标系统平移变换,把原点平移到窗口中心
painter.scale(side/300.0,side/300.0);//坐标系统比例变换,使绘制的图形随窗口的放大而放大
painter.scale(1,-1);//Y轴向上翻转,翻转成正常平面直角坐标系
painter.setPen(QPen(Qt::black,height()/600));
painter.drawLine(-2000,0,2000,0);
painter.drawLine(0,1500,0,-1500);
}