Qt与电脑管家4

news/2024/12/21 23:09:59/

折线图:

#ifndef LINE_CHART_H
#define LINE_CHART_H#include <QWidget>
#include <QPainter>
#include "circle.h"
class line_chart : public QWidget
{Q_OBJECT
public:explicit line_chart(QWidget *parent = nullptr);
protected:void paintEvent(QPaintEvent *event) override;
private:QVector<int> h;int max,min,sum;
signals:};#endif // LINE_CHART_H
#include "line_chart.h"
#include <QDebug>
line_chart::line_chart(QWidget *parent) : QWidget(parent)
{sum=0;for(int i=0;i<30;i++){if(i%5==0)h<<i;else{h<<0;}}//最大值,最小值for(int i=0;i<30;++i){if(i==0){max=h.at(i);min=h.at(i);}else{if(max<h.at(i))max=h.at(i);if(min>h.at(i))min=h.at(i);}sum+=h.at(i);}
}void line_chart::paintEvent(QPaintEvent *event)
{QPainter painter(this);painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing, true);//画背景painter.save();painter.setPen(Qt::NoPen);painter.setBrush(QBrush(QColor(255,255,255)));painter.drawRect(rect());painter.restore();//画横线painter.save();//确定条数//4,0:3//5,0:4int count=max-min-1;int x1,x2,y;x1=5;x2=width()-5;y=height()-10;int w=(height()-20)/count;QPen pen;pen.setColor(QColor(214, 223, 255));pen.setWidth(1);pen.setStyle(Qt::SolidLine);painter.setPen(pen);for(int i=0;i<count;++i){painter.drawLine(x1,y,x2,y);y=y-w;}painter.restore();//画蓝色折线painter.save();double w1=width()-20;x1=10;double space=w1/(h.count()-1);QVector<QLine> lines;QPen pen1;pen1.setColor(QColor(133, 159, 255));pen1.setWidth(2);pen1.setStyle(Qt::SolidLine);painter.setPen(pen1);painter.setBrush(QBrush(QColor(243, 246, 255)));double h1=(height()-20)/(max-min);//每一小块的长度painter.translate(0,height()-10-10);for(int i=0;i<h.count()-1;++i){double y1,y2;y1=(h.at(i)-min)*h1;//高度y2=(h.at(i+1)-min)*h1;//高度lines.append(QLine(x1,-y1,x1+space,-y2));x1+=space;}painter.drawLines(lines);painter.restore();}

窗体控件透明度

QT 窗体控件的透明度设置(三种方法)_qt paint setbrush 透明_chenyazhou88的博客-CSDN博客

    opacityEffect=new QGraphicsOpacityEffect(this);this->setGraphicsEffect(opacityEffect);opacityEffect->setOpacity(0.2);

自定义按钮

#ifndef BTN5_H
#define BTN5_H#include <QPushButton>
#include "btn1.h"
class btn5 : public btn1
{Q_OBJECT
public:btn5(QWidget * parent = nullptr);void set_normal_icon(QString icon);void init(QSize size,QSize hover_size);
protected:void paintEvent(QPaintEvent *) override;void enterEvent(QEvent *event) override;void leaveEvent(QEvent *event) override;
private:QString normal_icon;QSize icon_size,size,hover_size;bool hover;
signals:void mouse_enter();void mouse_leave();
};#endif // BTN5_H
#include "btn5.h"
#include <QDebug>
#include <QPainter>
#pragma execution_character_set("utf-8")
#pragma execution_character_set("utf-8")
btn5::btn5(QWidget * parent ): btn1(parent)
{init(QSize(50,50),QSize(150,50));icon_size=QSize(25,25);
}void btn5::set_normal_icon(QString icon)
{normal_icon=icon;
}void btn5::init(QSize s,QSize hover_s)
{size=s;hover_size=hover_s;QSizePolicy sizePolicy1(QSizePolicy::Fixed, QSizePolicy::Fixed);sizePolicy1.setHorizontalStretch(0);sizePolicy1.setVerticalStretch(0);sizePolicy1.setHeightForWidth(this->sizePolicy().hasHeightForWidth());this->setSizePolicy(sizePolicy1);//宽高this->setMinimumSize(size);this->setMaximumSize(size);hover=false;
}void btn5::enterEvent(QEvent *event)
{Q_UNUSED(event);qDebug()<<"进入事件发生";hover=true;//显示
}void btn5::leaveEvent(QEvent *event)
{Q_UNUSED(event);qDebug()<<"离开事件发生";hover=false;//隐藏
}void btn5::paintEvent(QPaintEvent *)
{QPainter painter(this);painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing, true);QPen pen;pen.setColor(QColor(230,230,230));pen.setStyle(Qt::SolidLine);pen.setWidth(1);//透明背景painter.save();painter.setPen(Qt::NoPen);painter.setBrush(QBrush(QColor(255,255,255,0)));painter.drawRect(rect());painter.restore();if(!hover){this->setMinimumSize(size);this->setMaximumSize(size);painter.save();//画圆角矩形painter.setPen(pen);painter.setBrush(QBrush(QColor(255,255,255)));double side=qMin(width(),height());painter.drawRoundedRect(rect(),side/2,side/2,Qt::AbsoluteSize);painter.restore();painter.save();//画图标QPixmap pix(normal_icon);pix=pix.scaled(icon_size,Qt::IgnoreAspectRatio);painter.translate(width()/2,height()/2);QRectF target(-icon_size.width()/2,-icon_size.height()/2,icon_size.width(),icon_size.height());QRectF source(0,0,icon_size.width(),icon_size.height());painter.drawPixmap(target,pix,source);painter.restore();}else{this->setMinimumSize(hover_size);this->setMaximumSize(hover_size);painter.save();//画圆角矩形painter.setPen(pen);painter.setBrush(QBrush(QColor(255,255,255)));double side=qMin(width(),height());painter.drawRoundedRect(rect(),side/2,side/2,Qt::AbsoluteSize);painter.restore();painter.save();//画图标QPixmap pix(normal_icon);pix=pix.scaled(icon_size,Qt::IgnoreAspectRatio);//图标所占宽度:与之前一样painter.translate(size.width()/2,height()/2);QRectF target(-icon_size.width()/2,-icon_size.height()/2,icon_size.width(),icon_size.height());QRectF source(0,0,icon_size.width(),icon_size.height());painter.drawPixmap(target,pix,source);painter.restore();//画文字painter.save();painter.translate(size.width(),height()/2);QFont font;font.setPointSize(10);painter.setFont(font);QPen pen;pen.setColor(QColor(50,50,50));painter.setPen(pen);painter.drawText(0,-height()/2,hover_size.width()-size.width(),height(),Qt::AlignLeft | Qt::AlignVCenter,text());painter.restore();}
}

 阶段性效果图:

 


http://www.ppmy.cn/news/1050666.html

相关文章

【LUBAN】【功能验证】至简投屏功能之Android有线连接方式测试

1、概述 至简投屏功能之Android有线连接方式支持至简自带应用至加的投屏功能和谷歌官方的Android auto功能。 支持的功能范围列举如下&#xff1a; 1、屏幕投屏&#xff08;支持自动旋转屏&#xff09;2、音视频播放&#xff08;抖音、百度地图等&#xff09;3、车机反控手机…

Reactor 第十篇 定制一个生产的WebClient

1 为什么要用 WebClient 刚开始尝试使用 Spring WebFlux 的时候&#xff0c;很多人都会使用 Mono.fromFuture() 将异步请求转成 Mono 对象&#xff0c;或者 Mono.fromSupplier() 将请求转成 MOno 对象&#xff0c;这两种方式在响应式编程中都是不建议的&#xff0c;都会阻塞当…

使用vscode编写插件-php语言

https://blog.csdn.net/qq_45701130/article/details/125206645 一、环境搭建 1、安装 Visual Studio Code 2、安装 Node.js 3、安装 Git 4、安装生产插件代码的工具&#xff1a;npm install -g yo generator-code 二、创建工程 yo code 选择项解释&#xff1a; 选择编写扩…

linux下c控制光标

最近在写进度条的需求&#xff0c;需要控制光标&#xff0c;用到下面的相关函数 // 清除屏幕#define CLEAR() printf("\033[2J")// 上移光标#define MOVEUP(x) printf("\033[%dA", (x))// 下移光标#define MOVEDOWN(x) printf("\033[%dB", (x))…

分类预测 | MATLAB实现NGO-DBN北方苍鹰优化深度置信网络多特征输入分类预测

分类预测 | MATLAB实现NGO-DBN北方苍鹰优化深度置信网络多特征输入分类预测 目录 分类预测 | MATLAB实现NGO-DBN北方苍鹰优化深度置信网络多特征输入分类预测效果一览基本介绍模型描述程序设计参考资料 效果一览 基本介绍 MATLAB实现NGO-DBN北方苍鹰优化深度置信网络多特征输入…

【jsthreeJS】入门three,并实现3D汽车展示厅,附带全码

首先放个最终效果图&#xff1a; 三维&#xff08;3D&#xff09;概念&#xff1a; 三维&#xff08;3D&#xff09;是一个描述物体在三个空间坐标轴上的位置和形态的概念。相比于二维&#xff08;2D&#xff09;只有长度和宽度的平面&#xff0c;三维增加了高度或深度这一维度…

机器学习使用场景

在计算机系统中&#xff0c;“经验”通常以“数据”的形式存在。因此&#xff0c;机器学习的主要内容&#xff0c;是关于在计算机上从数据中产生Function的算法&#xff0c;这个Function的作用是将将输入映射成合理的输出。例如给Function输入猫的图片&#xff0c;Function能够…

利用屏幕水印学习英语单词,无打扰英语单词学习

1、利用屏幕水印学习英语单词&#xff0c;不影响任何鼠标键盘操作&#xff0c;不影响工作 2、利用系统热键快速隐藏&#xff08;ALT1键 隐藏与显示&#xff09; 3、日积月累单词会有进步 4、软件下载地址: 免安装&#xff0c;代码未加密&#xff0c;安全的屏幕水印学习英语…