2022-05-31 09:21:56 +00:00
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "ui_mainwindow.h"
|
|
|
|
#include <QColorDialog>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QDialog>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QFontDialog>
|
|
|
|
#include <QInputDialog>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QProgressDialog>
|
|
|
|
bool enable = false;
|
|
|
|
bool drawing = false;
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
|
|
: QMainWindow(parent), ui(new Ui::MainWindow) {
|
|
|
|
ui->setupUi(this);
|
|
|
|
this->setProperty("canMove", false);
|
|
|
|
resize(600, 500); //窗口大小设置为600*500
|
|
|
|
pix = QPixmap(600, 500);
|
|
|
|
pix.fill(Qt::white);
|
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::~MainWindow() { delete ui; }
|
|
|
|
|
|
|
|
void MainWindow::on_styCor_triggered() //边框颜色
|
|
|
|
{
|
|
|
|
QPainter pp(&pix); // 根据鼠标指针前后两个位置就行绘制直线
|
|
|
|
pp.drawLine(
|
|
|
|
lastPoint,
|
|
|
|
endPoint); // 让前一个坐标值等于后一个坐标值,这样就能实现画出连续的线
|
|
|
|
lastPoint = endPoint;
|
|
|
|
QPainter painter(this);
|
|
|
|
painter.drawPixmap(0, 0, pix);
|
|
|
|
}
|
|
|
|
void MainWindow::paintEvent(QPaintEvent *event) {
|
|
|
|
QPainter painter(this);
|
2022-06-08 05:02:43 +00:00
|
|
|
painter.drawLine(QPoint(100, 100), QPoint(200, 200));
|
|
|
|
|
|
|
|
QPen pen(Qt::green, 5, Qt::DotLine, Qt::RoundCap, Qt::RoundJoin);
|
|
|
|
painter.setPen(pen);
|
|
|
|
QRectF rect(170.0, 140.0, 180.0, 60.0);
|
|
|
|
int startAngle = 30 * 16;
|
|
|
|
int spanAngle = 120 * 16;
|
|
|
|
painter.drawArc(rect, startAngle, spanAngle);
|
2022-05-31 09:21:56 +00:00
|
|
|
|
2022-06-08 05:02:43 +00:00
|
|
|
pen.setWidth(1);
|
|
|
|
pen.setStyle(Qt::SolidLine);
|
|
|
|
painter.setPen(pen);
|
|
|
|
painter.drawRect(260, 220, 250, 240);
|
|
|
|
QBrush brush(QColor(0, 0, 255), Qt::Dense4Pattern);
|
|
|
|
painter.setBrush(brush);
|
|
|
|
painter.drawEllipse(220, 220, 250, 150);
|
|
|
|
|
|
|
|
static const QPointF points[4] = {
|
|
|
|
QPointF(270.0, 180.0), QPointF(290.0, 110.0), QPointF(350.0, 130.0),
|
|
|
|
QPointF(390.0, 170.0)};
|
|
|
|
painter.drawPolygon(points, 4);
|
|
|
|
|
|
|
|
painter.fillRect(QRect(10, 100, 150, 20), QBrush(Qt::darkYellow));
|
|
|
|
painter.eraseRect(QRect(50, 0, 50, 120));
|
2022-05-31 09:21:56 +00:00
|
|
|
}
|
2022-06-08 05:02:43 +00:00
|
|
|
// void MainWindow::paintEvent(QPaintEvent *event) {
|
|
|
|
// if (enable)
|
|
|
|
// switch (drawStatus) {
|
|
|
|
// case line:
|
|
|
|
// QPainter pp(&pix); // 根据鼠标指针前后两个位置就行绘制直线
|
|
|
|
// pp.drawLine(
|
|
|
|
// lastPoint,
|
|
|
|
// endPoint); //
|
|
|
|
// 让前一个坐标值等于后一个坐标值,这样就能实现画出连续的线
|
|
|
|
// enable = false;
|
|
|
|
// }
|
|
|
|
// QPainter painter(this);
|
|
|
|
// painter.drawPixmap(0, 0, pix);
|
|
|
|
|
|
|
|
// drawStatus = idle;
|
|
|
|
//}
|
2022-05-31 09:21:56 +00:00
|
|
|
void MainWindow::drawLineTriger() { drawStatus = line; }
|
|
|
|
|
|
|
|
void MainWindow::on_drawLine_triggered() {
|
|
|
|
enable = true;
|
|
|
|
drawStatus = line;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::mousePressEvent(QMouseEvent *event) {
|
|
|
|
|
|
|
|
if (event->button() == Qt::LeftButton) //鼠标左键按下
|
|
|
|
if (drawing) {
|
|
|
|
endPoint = event->pos();
|
|
|
|
drawing = false;
|
|
|
|
enable = true;
|
|
|
|
update();
|
|
|
|
} else {
|
|
|
|
drawing = true;
|
|
|
|
lastPoint = event->pos();
|
|
|
|
}
|
|
|
|
}
|