当前位置: 首页 > news >正文

QT第六天

要求:使用QT绘图,完成仪表盘绘制,如下图。

素材

 

 运行效果:

代码: 

widget.h

#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>
#include <QPainter>
#include <QPen>QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACEclass Widget : public QWidget
{Q_OBJECTpublic:Widget(QWidget *parent = nullptr);~Widget();void paintEvent(QPaintEvent *event) override;public slots:void horizontalSliderValueChangedSlot(int);private:Ui::Widget *ui;
};
#endif // WIDGET_H

 widget.cpp

#include "widget.h"
#include "ui_widget.h"Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget)
{ui->setupUi(this);ui->horizontalSlider->setValue(0);ui->horizontalSlider->setMaximum(100);ui->horizontalSlider->setMinimum(0);connect(ui->horizontalSlider, SIGNAL(valueChanged(int) ), this, SLOT(horizontalSliderValueChangedSlot(int)));
}Widget::~Widget()
{delete ui;
}void Widget::paintEvent(QPaintEvent *event)
{QPainter p(this);double R  = this->width()*0.375;p.translate(this->width()/2,this->height()/2);p.drawPixmap(-R*1.01,-R*0.98,2*R,2*R,QPixmap(":/rs/Pan.png"));p.rotate(ui->horizontalSlider->value() * 2.8 + 130);p.drawPixmap(-R*0.08,-R*0.085,R*0.72,R*0.15,QPixmap(":/rs/Point.png"));}void Widget::horizontalSliderValueChangedSlot(int)
{this->update();
}

widget.ui

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"><class>Widget</class><widget class="QWidget" name="Widget"><property name="geometry"><rect><x>0</x><y>0</y><width>400</width><height>400</height></rect></property><property name="minimumSize"><size><width>400</width><height>400</height></size></property><property name="sizeIncrement"><size><width>0</width><height>0</height></size></property><property name="baseSize"><size><width>0</width><height>0</height></size></property><property name="windowTitle"><string>仪表盘</string></property><layout class="QVBoxLayout" name="verticalLayout"><property name="leftMargin"><number>100</number></property><property name="topMargin"><number>10</number></property><property name="rightMargin"><number>100</number></property><property name="bottomMargin"><number>10</number></property><item><spacer name="verticalSpacer"><property name="orientation"><enum>Qt::Vertical</enum></property><property name="sizeHint" stdset="0"><size><width>20</width><height>40</height></size></property></spacer></item><item><widget class="QSlider" name="horizontalSlider"><property name="orientation"><enum>Qt::Horizontal</enum></property></widget></item></layout></widget><resources/><connections/>
</ui>
http://www.lryc.cn/news/285517.html

相关文章:

  • linux 安装 grafana
  • “GPC爬虫池有用吗?
  • Kotlin协程的JVM实现源码分析(下)
  • js实现九九乘法表
  • HarmonyOS鸿蒙应用开发(三、轻量级配置存储dataPreferences)
  • 基于 IDEA 进行 Maven 工程构建
  • 牛客周赛 Round 17 解题报告 | 珂学家 | 枚举贪心 + 二分最短路
  • 喝口水都长胖?原来是“胖菌”惹的祸?!
  • 【C++干货基地】namespace超越C语言的独特魅力(文末送书)
  • 做一个简单的倒计时
  • 微服务环境搭建:docker+nacos单机
  • Opencv轮廓检测运用与理解
  • Java 8的新特性简单分享(后续有系列篇~敬请期待)
  • 计算机网络-计算机网络的概念 功能 发展阶段 组成 分类
  • 246.【2023年华为OD机试真题(C卷)】分月饼(动态规划-JavaPythonC++JS实现)
  • java大数据hadoop2.9.2 Linux安装mariadb和hive
  • Docker部署微服务问题及解决
  • Android: alarm定时很短时,比如500ms,测试执行mPowerManager.forceSuspend()后,系统不会suspend
  • 一个简单好用的C语言单元测试框架-Unity
  • ubuntu系统 vscode 配置c/c++调试环境
  • 算法练习-A+B/财务管理/实现四舍五入/牛牛的菱形字符(题目链接+题解打卡)
  • XSS语句
  • AD导出BOM表 导出PDF
  • linux 的nobody是什么用户? 对安全有没有影响?
  • 2024年华数杯国际数学建模B 光伏电(Problem B: Photovoltaic Power)完整思路以及源代码分享
  • 在 Spring MVC 中,用于接收前端传递的参数的注解有以下几种
  • K8s常用命令
  • MySQL的基本操作
  • 【b站咸虾米】chapter4_vue组件_新课uniapp零基础入门到项目打包(微信小程序/H5/vue/安卓apk)全掌握
  • Java网络编程——UDP通信原理