您的位置:首页 > 科技 > 能源 > 免费白嫖国外服务器app_建筑工程人才培训网_百度网站的优化方案_龙岩seo

免费白嫖国外服务器app_建筑工程人才培训网_百度网站的优化方案_龙岩seo

2025/3/10 16:36:19 来源:https://blog.csdn.net/qq_64881918/article/details/146054273  浏览:    关键词:免费白嫖国外服务器app_建筑工程人才培训网_百度网站的优化方案_龙岩seo
免费白嫖国外服务器app_建筑工程人才培训网_百度网站的优化方案_龙岩seo

widget.h

#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>
#include <QPaintEvent>
#include <QPainter>
#include <QDebug>
#include <QMouseEvent>
#include <QLine>
#include <QVector>
#include <QColorDialog>
#include <QKeyEvent>struct Lineinfo{QLine line;QColor color;int width;
};QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACEclass Widget : public QWidget
{Q_OBJECTpublic:Widget(QWidget *parent = nullptr);~Widget();private:Ui::Widget *ui;QPainter painter;QPen pen;QPoint start;QPoint end;QVector<Lineinfo> lines;QVector<QPoint> lines_last;QColor color;QColor recolor;int width=1;int re=0;protected:virtual void paintEvent(QPaintEvent *event) override;virtual void mouseMoveEvent(QMouseEvent *event) override;virtual void mousePressEvent(QMouseEvent *event) override;virtual void mouseReleaseEvent(QMouseEvent *event) override;virtual void keyPressEvent(QKeyEvent *event) override;private slots:void on_pushButton_clicked();void on_pushButton_2_clicked();void on_pushButton_3_clicked();void on_pushButton_4_clicked();void on_pushButton_5_clicked();void on_pushButton_6_clicked();
};
#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);
}Widget::~Widget()
{delete ui;
}void Widget::paintEvent(QPaintEvent *event)
{painter.begin(this);for(auto perline:lines){pen.setColor(perline.color);pen.setWidth(perline.width);painter.setPen(pen);painter.drawLine(perline.line);}painter.end();
}void Widget::mouseMoveEvent(QMouseEvent *event)
{end = event->pos();QLine line(start,end);Lineinfo lineinfo;lineinfo.color=color;lineinfo.line=line;lineinfo.width=width;lines.append(lineinfo);// 将鼠标绘制的每一跟线段存入QVector里面,也就是lines里面start = end;update();
}void Widget::mousePressEvent(QMouseEvent *event)
{start = event->pos();lines_last<<start;
}void Widget::mouseReleaseEvent(QMouseEvent *event)
{end = event->pos();}void Widget::keyPressEvent(QKeyEvent *event)
{if(event->modifiers() == Qt::ControlModifier && event->key() == Qt::Key_Z){if(!lines_last.isEmpty()){while(lines.last().line.p1() != lines_last.last()){lines.removeLast();}lines_last.removeLast();lines.removeLast();}}update();
}// 打开调色板
void Widget::on_pushButton_clicked()
{color = QColorDialog::getColor(Qt::black,this,"选择颜色");
}void Widget::on_pushButton_2_clicked()
{width = 1;if(re==1){color=recolor;}
}void Widget::on_pushButton_3_clicked()
{width = 5;if(re==1){color=recolor;}
}void Widget::on_pushButton_4_clicked()
{width = 10;if(re==1){color=recolor;}
}void Widget::on_pushButton_5_clicked()
{recolor=color;color=palette().color(QPalette::Window);re=1;
}

 

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com