#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPushButton>
#include <QMessageBox>
#include <QGraphicsDropShadowEffect>
#include <QDebug>
#include <QPainter>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->pushButton->setFocusPolicy(Qt::NoFocus);
connect(ui->pushButton, SIGNAL(pressed()), this, SLOT(paintBorder()));
connect(ui->pushButton, SIGNAL(released()), this, SLOT(paintBorder()));
}
MainWindow::~MainWindow()
{
delete ui;
}
/*
* 前提条件
* border图绝对的中心对称与轴对称
* -----------
* 重要参数
* -----------
* border_width: 边缘宽度
* border_radius: 边缘转角半径
*
*/
void MainWindow::paintEvent(QPaintEvent *event) {
QPainter painter(this);
QPixmap background = QPixmap(":/image/radius_border.png");
int background_width = background.width(); // 背景图片宽度
int background_height = background.height(); // 背景图片高度
int border_width = 5;
int border_radius = 5;
int original_border = 1;
int corner_width = border_width + border_radius;
int corner_height = border_width + border_radius;
/* 以顺时针方向旋转的边界 */
QPixmap leftTop = background.copy(0, 0, corner_width, corner_height);
QPixmap top = background.copy(corner_width, 0, background_width - 2 * corner_width, border_width);
QPixmap rightTop = background.copy(background_width - corner_width, 0, corner_width, corner_height);
QPixmap right = background.copy(background_width - border_width, corner_height, border_width,
background_height - 2 * corner_height);
QPixmap rightBottom = background.copy(background_width - corner_width, background_height - corner_height,
corner_width, corner_height);
QPixmap bottom = background.copy(corner_width, background_height - border_width,
background_width - 2 * corner_width, border_width);
QPixmap leftBottom = background.copy(0, background_height - corner_height, corner_width, corner_height);
QPixmap left = background.copy(0, corner_height, border_width, background_height - 2 * corner_height);
if(ui->pushButton->isDown()) {
QRect rect = ui->lineEdit->geometry();
int startX = rect.left();
int endX = rect.right();
int startY = rect.top();
int endY = rect.bottom();
int width = rect.width();
int height = rect.height();
painter.drawPixmap(startX - border_width, startY - border_width, leftTop);
painter.drawPixmap(startX + border_radius, startY - border_width,
width - 2 * border_radius - original_border, border_width, top);
painter.drawPixmap(endX - border_radius, startY - border_width, rightTop);
painter.drawPixmap(endX, startY + border_radius, border_width,
height - 2 * border_radius - original_border, right);
painter.drawPixmap(endX - border_radius, endY - border_radius, rightBottom);
painter.drawPixmap(startX + border_radius, endY , width - 2 * border_radius - original_border,
border_width, bottom);
painter.drawPixmap(startX - border_width, endY - border_width, leftBottom);
painter.drawPixmap(startX - border_width, startY + border_radius, border_width,
height - 2 * border_radius - original_border, left);
}
if(ui->lineEdit->hasFocus()) {
}
if(ui->lineEdit_2->hasFocus()) {
}
}
void MainWindow::paintBorder() {
this->update();
}

lihancheng
- 粉丝: 8
最新资源
- 如何通过AI+数智应用技术解决科技管理中的价值创造难题?.docx
- 如何通过AI+数智应用科技管理系统实现高效管理与价值创造的双重目标?.docx
- 如何通过AI+数智应用科技平台市场化体系建设解决资源不足问题?.docx
- 如何通过AI+数智应用市场化科技平台建设与运营解决资源整合难题?.docx
- 如何通过AI+数智应用全流程创新管理提升科技管理系统的智能化水平?.docx
- 如何通过AI+数智应用科技平台市场化体系实现可持续发展?.docx
- 如何通过AI+数智应用提升科技平台的服务质量和用户体验?.docx
- 如何通过AI+数智应用手段提升科技活动组织效率与资源匹配精准度?.docx
- 如何通过AI+数智应用手段提升科技管理的智能化水平?.docx
- 为什么说AI+数智应用科技管理服务是未来政府科技评估的发展趋势?.docx
- 现有的科技管理系统为何大多缺乏服务能力?如何利用AI+数智应用自主驱动和创造价值?.docx
- 如何通过AI+数智应用政府创新监测提升科技管理系统的智能化水平?.docx
- 政府创新规划下,如何让AI+数智应用科技管理系统既智能又能有效创造价值?.docx
- 政府创新规划涉及多方面,AI+数智应用科技管理系统如何助力协同发展?.docx
- 在技术创新管理中,如何借助AI+数智应用突破传统科技管理系统只管理没服务的限制?.docx
- 政府创新评估中,如何借助AI+数智应用技术实现科技管理工作效率的大幅提升?.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈


