当前位置:网站首页>记一次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);
}
}
实现结果:

边栏推荐
猜你喜欢

Pytorch study notes 13 - Basic_RNN

力扣.两数之和/四数相加||

MySQL free installation download and configuration tutorial

Pytorch learning notes 09 - multiple classification problem

【Latex】TexLive+VScode+SumatraPDF 配置LaTex编辑环境

C语言静态变量static

Cholesterol-PEG-Thiol CLS-PEG-SH Cholesterol-Polyethylene Glycol-Sulfhydryl

DSPE-PEG-Azide DSPE-PED-N3 Phospholipid-Polyethylene Glycol-Azide Lipid PFG

2022 SQL big factory high-frequency practical interview questions (detailed analysis)

WIN10,配置adb环境
随机推荐
数据分析之SQL面试真题
力扣.有效的字母异位词
Pytorch study notes 13 - Basic_RNN
Redis-Hash
Log jar package conflict, and its solution
Tensorflow steps on the pit while using it
Natural language processing related list
UR3机器人运动学分析之逆运动学分析
化学试剂磷脂-聚乙二醇-氨基,DSPE-PEG-amine,CAS:474922-26-4
mPEG-DMPE 甲氧基-聚乙二醇-双肉豆蔻磷脂酰乙醇胺用于形成隐形脂质体
Research reagents Cholesterol-PEG-Maleimide, CLS-PEG-MAL, Cholesterol-PEG-Maleimide
Hyperparameter Optimization - Excerpt
box-shadow related properties
CSDN上markdown编写的一些便捷操作
十分钟教你玩转分支语句!!!!!小白速进,新手福利!!
Unity Text一个简单的输入特效
Pytorch study notes 10 - detailed explanation of convolutional neural network and application of multi-classification task of mnist dataset
关于网络安全法的个人理解
Cholesterol-PEG-DBCO Cholesterol-Polyethylene Glycol-Diphenylcyclooctyne Chemical Reagent
C语言结构体(必须掌握版)