• 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;
                }
            }
  • 相关阅读:
    Redis 学习目录
    Knockout 官网学习文档目录
    C# 知识点回忆..
    爬虫-HtmlAgilityPack
    net core 3.1 知识累积
    共享文件夹(局域网)报错:The username or password is incorrect
    使用 Beyond Compare 工具比较合并 TFS 管理的代码
    创建索引,SQL优化
    LINQ SelectMany代替for循环赋值,把联合查询的值赋值给第1个集合
    判断文件编码
  • 原文地址:https://www.cnblogs.com/duxie/p/11781279.html
Copyright © 2020-2023  润新知