码迷,mamicode.com
首页 > 其他好文 > 详细

Qt 利用飞机图片画五边形

时间:2019-11-02 13:27:32      阅读:94      评论:0      收藏:0      [点我收藏+]

标签:练习   指正   label   定时器   理想   qpi   com   pix   code   

最近练习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 利用飞机图片画五边形

标签:练习   指正   label   定时器   理想   qpi   com   pix   code   

原文地址:https://www.cnblogs.com/duxie/p/11781279.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!