Qt 利用飞机图片画五边形
Posted duxie
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Qt 利用飞机图片画五边形相关的知识,希望对你有一定的参考价值。
最近练习Qt,需要一个飞机在屏幕上画五边形。虽然达到的效果不是非常的理想,但是勉强还是达到了效果,欢迎大家指正。用到的飞机图片如下。
第一步:初始化,在构造函数里面,把图片向左旋转18°
// 向左旋转18°
matrix.rotate(-18);
ui.label->setPixmap(QPixmap("C:\\Users\\Administrator.USER-20190313RI\\Desktop\\img\\life.png").transformed(matrix, Qt::SmoothTransformation));
第二步:在定时器里面执行如下代码
switch(flag) { case 1: { if (num == 10) { num = 0; flag = 2; matrix.rotate(72); ui.label->setPixmap(QPixmap("C:\\Users\\Administrator.USER-20190313RI\\Desktop\\img\\life.png").transformed(matrix, Qt::SmoothTransformation)); } int x = ui.label->x() - 8; int y = ui.label->y() - 10; ui.label->move(x, y); num++; break; } case 2: { if (num == 10) { num = 0; flag = 3; matrix.rotate(72); ui.label->setPixmap(QPixmap("C:\\Users\\Administrator.USER-20190313RI\\Desktop\\img\\life.png").transformed(matrix, Qt::SmoothTransformation)); } int x = ui.label->x() + 15; int y = ui.label->y() - 10; ui.label->move(x, y); num++; break; } case 3: { if (num == 10) { num = 0; flag = 4; matrix.rotate(72); ui.label->setPixmap(QPixmap("C:\\Users\\Administrator.USER-20190313RI\\Desktop\\img\\life.png").transformed(matrix, Qt::SmoothTransformation)); } int x = ui.label->x() + 15; int y = ui.label->y() + 10; ui.label->move(x, y); num++; break; } case 4: { if (num == 10) { num = 0; flag = 5; matrix.rotate(72); ui.label->setPixmap(QPixmap("C:\\Users\\Administrator.USER-20190313RI\\Desktop\\img\\life.png").transformed(matrix, Qt::SmoothTransformation)); } int x = ui.label->x() - 8; int y = ui.label->y() + 10; ui.label->move(x, y); num++; break; } case 5: { if (num == 10) { num = 0; flag = 1; matrix.rotate(72); ui.label->setPixmap(QPixmap("C:\\Users\\Administrator.USER-20190313RI\\Desktop\\img\\life.png").transformed(matrix, Qt::SmoothTransformation)); } int x = ui.label->x() - 14; int y = ui.label->y(); ui.label->move(x, y); num++; break; } default: { break; } }
以上是关于Qt 利用飞机图片画五边形的主要内容,如果未能解决你的问题,请参考以下文章