1 Star 0 Fork 1

shiver/qt_phone_helper

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
paintwidget.cpp 3.62 KB
一键复制 编辑 原始数据 按行查看 历史
JianBiHua 提交于 2019-03-12 11:26 . qt phone helper
#include "paintwidget.h"
#include <QPainter>
PaintWidget::PaintWidget(QWidget *parent) : QWidget(parent)
{
// 默认模式
backgroundMode = 0;
this->setMouseTracking (true);
}
void PaintWidget::setBackgroundMode (int m) {
backgroundMode = m;
// 重新绘制
update ();
}
void PaintWidget::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
if (backgroundMode == 0 ||
backgroundMode == -1) {
paintBackGroundMode0 ();
} else if (backgroundMode == 1) {
paintBackGroundMode1 ();
} else if (backgroundMode == 2) {
paintBackGroundMode2 ();
}
}
void PaintWidget::paintBackGroundMode0 () {
QPainter painter(this);
// 反走样
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setPen(QPen(QColor(0x00,0xff,0x00,0x00)));
painter.setBrush(QBrush(QColor(0xF1, 0xF1, 0xF1, 0xFF)));
// 各个点的坐标
static const QPointF points[4] = {QPointF(0, 0),
QPointF(this->width (), 0),
QPointF(this->width (), this->height ()),
QPointF(0, this->height ())};
// 绘制多边形
painter.drawPolygon(points, 4);
//
// 设置画笔颜色
QPainter painter2(this);
// 反走样
painter2.setRenderHint(QPainter::Antialiasing, true);
painter2.setPen(QColor(0xDB, 0xDB, 0xDB));
//绘制直线
painter2.drawLine(QPointF(width ()-1, 0),
QPointF(width()-1, height()));
}
void PaintWidget::paintBackGroundMode1 () {
QPainter painter(this);
// 反走样
painter.setRenderHint(QPainter::Antialiasing, true);
// 设置画笔颜色
painter.setPen(QColor(0x00,0xff,0x00,0x00));
//painter.setPen(QPen(Qt::white,1,Qt::SolidLine,Qt::RoundCap));
painter.setBrush(QBrush(QColor(0x42, 0xB7, 0x6A)));
// 各个点的坐标
static const QPointF points[7] = {QPointF(0, 0),
QPointF(this->width (), 0),
QPointF(this->width (),10),
QPointF(this->width ()-5, 14),
QPointF(this->width (), 18),
QPointF(this->width (), 28),
QPointF(0, 28)};
// 绘制多边形
painter.drawPolygon(points, 7);
}
void PaintWidget::paintBackGroundMode2 () {
QPainter painter(this);
// 反走样
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setPen(QPen(QColor(0x00,0xff,0x00,0x00)));
painter.setBrush(QBrush(QColor(0xA9, 0xF2, 0xC2, 0xFF)));
// 各个点的坐标
static const QPointF points[4] = {QPointF(0, 0),
QPointF(this->width (), 0),
QPointF(this->width (), this->height ()),
QPointF(0, this->height ())};
// 绘制多边形
painter.drawPolygon(points, 4);
//
// 设置画笔颜色
QPainter painter2(this);
// 反走样
painter2.setRenderHint(QPainter::Antialiasing, true);
painter2.setPen(QColor(0xDB, 0xDB, 0xDB));
//绘制直线
painter2.drawLine(QPointF(width ()-1, 0),
QPointF(width()-1, height()));
}
void PaintWidget::enterEvent(QEvent * event)//进入事件
{
if (backgroundMode != 1 &&
backgroundMode != -1) {
backgroundMode = 2;
update ();
}
}
void PaintWidget::leaveEvent(QEvent * event) {
if (backgroundMode != 1 &&
backgroundMode != -1) {
backgroundMode = 0;
update ();
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/shiver/qt_phone_helper.git
git@gitee.com:shiver/qt_phone_helper.git
shiver
qt_phone_helper
qt_phone_helper
master

搜索帮助