当前位置:网站首页>记一次QT 2D 画图 实现3D动态效果
记一次QT 2D 画图 实现3D动态效果
2022-07-31 05:18:00 【Awake1234】
最近在学习古老的QT开发手册,其中有一节是使用QT画图来实现正弦函数的小demo,稍微改变了一点,结果实现的结果超出了预期的想象,实现了3D的效果特此记录
//头文件
class drawDemo : public QWidget
{
Q_OBJECT
public:
explicit drawDemo(QWidget *parent = nullptr);
~drawDemo();
public slots:
void flushBuff();
protected:
virtual void paintEvent(QPaintEvent *);
private:
int buffer[200];
QTimer * timer;
const double PI = 3.1415926;
Ui::drawDemo *ui;
};
#endif // DRAWDEMO_H
//cpp
drawDemo::drawDemo(QWidget *parent) :
QWidget(parent),
ui(new Ui::drawDemo)
{
ui->setupUi(this);
this->setWindowTitle("test");
this->setStyleSheet("QWidget{background:#000000;}");
this->setGeometry(QRect(40,40,402,252));
for(int i = 0;i<200;i++)
{
buffer[i] = static_cast<int>((sin((i*PI)/100)*100));
}
timer = new QTimer();
connect(timer,&QTimer::timeout,this,&drawDemo::flushBuff);
timer->start(30);
}
drawDemo::~drawDemo()
{
delete ui;
}
void drawDemo::flushBuff()
{
int temp = buffer[0];
for(int i = 0;i<200;i++)
{
buffer[i]=buffer[i+1];
}
buffer[199]=temp;
update();
}
void drawDemo::paintEvent(QPaintEvent *)
{
QPainter painter(this);
QPoint beginPoint;
QPoint endPoint;
painter.setPen(Qt::blue);
for(int i = 0;i<199;i++)
{
beginPoint.setX(2*i);
beginPoint.setY(buffer[i]+125);
endPoint.setX(2*i+i);
endPoint.setY(buffer[i+1]+125);
painter.drawLine(beginPoint,endPoint);
}
}
实现结果:
边栏推荐
- Redis-哈希
- 堆和栈的区别
- Chemical Reagent Phospholipid-Polyethylene Glycol-Amino, DSPE-PEG-amine, CAS: 474922-26-4
- Learn how to get a database connection with JDBC
- Solution for MySQL The table is full
- CAS: 1403744-37-5 DSPE-PEG-FA Phospholipid-Polyethylene Glycol-Folic Acid for Scientific Research
- 数据分析之SQL面试真题
- Cholesterol-PEG-NHS NHS-PEG-CLS cholesterol-polyethylene glycol-active ester can modify small molecular materials
- Incredibuild 宣布支持 Yocto
- 化学试剂磷脂-聚乙二醇-氨基,DSPE-PEG-amine,CAS:474922-26-4
猜你喜欢
螺旋矩阵Ⅱ
CAS: 1403744-37-5 DSPE-PEG-FA Phospholipid-Polyethylene Glycol-Folic Acid for Scientific Research
[已解决]ssh连接报:Bad owner or permissions on C:\\Users/XXX/.ssh/config
Pytorch learning notes 09 - multiple classification problem
[Solved] ssh connection report: Bad owner or permissions on C:\\Users/XXX/.ssh/config
mPEG-DSPE 178744-28-0 Methoxy-polyethylene glycol-phosphatidylethanolamine linear PEG phospholipids
box-shadow相关属性
Image binarization processing of opencv
UE5 最新动态虚幻引擎全新版本引爆互联网
国际站卖家大促攻略,只需要做好这几件事
随机推荐
CAS:474922-22-0 Maleimide-PEG-DSPE 磷脂-聚乙二醇-马来酰亚胺简述
测试CSDN积分需求
常见网络攻击与防御方法
Wangeditor rich text editor to upload pictures and solve cross-domain problems
Shell/Vim related list
实现离线文件推流成rtsp 2
Cholesterol-PEG-Thiol CLS-PEG-SH 胆固醇-聚乙二醇-巯基
mPEG-DSPE 178744-28-0 甲氧基-聚乙二醇-磷脂酰乙醇胺线性PEG磷脂
Introduction to CLS-PEG-FITC Fluorescein-PEG-CLS Cholesterol-PEG-Fluorescein
box-shadow相关属性
ImportError: cannot import name ‘Xxxx‘ from partially initialized module ‘xx.xx.xx‘
解决nx安装 jtop问题
DSPE-PEG-Biotin,CAS:385437-57-0,磷脂-聚乙二醇-生物素可延长循环半衰期
力扣.两数之和/四数相加||
浏览器中的画中画(Picture-in-Picture)API
四种常见的POST提交数据方式
Cholesterol-PEG-Acid CLS-PEG-COOH 胆固醇-聚乙二醇-羧基修饰肽类化合物
The array technique, my love
能否更上一层楼?探究 CMake 争论
Cholesterol-PEG-DBCO Cholesterol-Polyethylene Glycol-Diphenylcyclooctyne Chemical Reagent