Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
mahuifa
QMDemo
提交
6bbade06
Q
QMDemo
项目概览
mahuifa
/
QMDemo
通知
1
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Q
QMDemo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6bbade06
编写于
7月 14, 2022
作者:
mahuifa
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
新功能:实现QPainter基本绘图Demo部件即函数命名
上级
ee36f95c
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
234 addition
and
108 deletion
+234
-108
PaintingDemo/basicdrawing/basicdrawing.pro
PaintingDemo/basicdrawing/basicdrawing.pro
+11
-15
PaintingDemo/basicdrawing/renderarea.cpp
PaintingDemo/basicdrawing/renderarea.cpp
+17
-0
PaintingDemo/basicdrawing/renderarea.h
PaintingDemo/basicdrawing/renderarea.h
+20
-1
PaintingDemo/basicdrawing/widget.cpp
PaintingDemo/basicdrawing/widget.cpp
+86
-0
PaintingDemo/basicdrawing/widget.h
PaintingDemo/basicdrawing/widget.h
+13
-0
PaintingDemo/basicdrawing/widget.ui
PaintingDemo/basicdrawing/widget.ui
+87
-92
未找到文件。
PaintingDemo/basicdrawing/basicdrawing.pro
浏览文件 @
6bbade06
...
...
@@ -33,18 +33,14 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin
!
isEmpty
(
target
.
path
)
:
INSTALLS
+=
target
#
程序版本
VERSION
=
1.0
.
0.0
#
程序图标
#
RC_ICONS
=
app
.
ico
#
公司名称
QMAKE_TARGET_COMPANY
=
"company"
#
程序说明
QMAKE_TARGET_DESCRIPTION
=
"test app"
#
版权信息
QMAKE_TARGET_COPYRIGHT
=
"Copyright(C) 2017"
#
程序名称
QMAKE_TARGET_PRODUCT
=
"app"
#
程序语言
#
0
x0800代表和系统当前语言一致
RC_LANG
=
0
x0800
contains
(
QT_ARCH
,
i386
){
#
使用
32
位编译器
DESTDIR
=
$$
PWD
/../
bin
#
程序输出路径
}
else
{
DESTDIR
=
$$
PWD
/../
bin64
#
使用
64
位编译器
}
#
msvc
编译器使用
utf
-
8
编码(好像只在
msvc2017以后才有效
)
msvc
{
QMAKE_CFLAGS
+=
/
utf
-
8
QMAKE_CXXFLAGS
+=
/
utf
-
8
}
PaintingDemo/basicdrawing/renderarea.cpp
浏览文件 @
6bbade06
...
...
@@ -4,6 +4,7 @@
#include <QFile>
#include <QPainter>
#include <QTextDocument>
#include <QWheelEvent>
RenderArea
::
RenderArea
(
QWidget
*
parent
)
:
QWidget
(
parent
)
{
...
...
@@ -16,3 +17,19 @@ void RenderArea::paintEvent(QPaintEvent *event)
{
}
/**
* @brief 鼠标滚轮缩放事件
* @param event
*/
void
RenderArea
::
wheelEvent
(
QWheelEvent
*
event
)
{
if
(
event
->
angleDelta
().
y
()
>
0
)
// 放大
{
}
else
// 缩小
{
}
QWidget
::
wheelEvent
(
event
);
}
PaintingDemo/basicdrawing/renderarea.h
浏览文件 @
6bbade06
...
...
@@ -2,10 +2,28 @@
#define RENDERAREA_H
#include <QWidget>
#include <QStyle>
class
RenderArea
:
public
QWidget
{
Q_OBJECT
public:
// 绘制形状
enum
Shape
{
Line
,
Points
,
Polyline
,
Polygon
,
Rect
,
RoundedRect
,
Ellipse
,
Arc
,
Chord
,
Pie
,
Path
,
Text
,
Pixmap
};
Q_ENUM
(
Shape
)
// 该宏向元对象系统注册一个枚举类型,便于通过QMetaEnum获取枚举信息
public:
explicit
RenderArea
(
QWidget
*
parent
=
nullptr
);
...
...
@@ -15,6 +33,7 @@ public slots:
protected:
void
paintEvent
(
QPaintEvent
*
event
)
override
;
void
wheelEvent
(
QWheelEvent
*
event
)
override
;
QByteArray
m_html
;
};
...
...
PaintingDemo/basicdrawing/widget.cpp
浏览文件 @
6bbade06
#include "widget.h"
#include "ui_widget.h"
#include "renderarea.h"
#include <QDebug>
#include <QMetaEnum>
Widget
::
Widget
(
QWidget
*
parent
)
:
QWidget
(
parent
)
,
ui
(
new
Ui
::
Widget
)
{
ui
->
setupUi
(
this
);
init
();
}
Widget
::~
Widget
()
...
...
@@ -15,6 +20,87 @@ Widget::~Widget()
void
Widget
::
init
()
{
// 获取画图形状Shape枚举名称和值,写入下拉框
QMetaEnum
metaEnum
=
QMetaEnum
::
fromType
<
RenderArea
::
Shape
>
();
for
(
int
i
=
0
;
i
<
metaEnum
.
keyCount
();
++
i
)
{
ui
->
com_shape
->
addItem
(
metaEnum
.
key
(
i
),
metaEnum
.
value
(
i
));
}
// 画笔样式枚举
metaEnum
=
QMetaEnum
::
fromType
<
Qt
::
PenStyle
>
();
for
(
int
i
=
0
;
i
<
metaEnum
.
keyCount
();
++
i
)
{
ui
->
com_penStyle
->
addItem
(
metaEnum
.
key
(
i
),
metaEnum
.
value
(
i
));
}
// 画笔笔帽样式枚举
metaEnum
=
QMetaEnum
::
fromType
<
Qt
::
PenCapStyle
>
();
for
(
int
i
=
0
;
i
<
metaEnum
.
keyCount
();
++
i
)
{
ui
->
com_penCapStyle
->
addItem
(
metaEnum
.
key
(
i
),
metaEnum
.
value
(
i
));
}
// 线段转角处连接样式枚举
metaEnum
=
QMetaEnum
::
fromType
<
Qt
::
PenJoinStyle
>
();
for
(
int
i
=
0
;
i
<
metaEnum
.
keyCount
();
++
i
)
{
ui
->
com_penJoinStyle
->
addItem
(
metaEnum
.
key
(
i
),
metaEnum
.
value
(
i
));
}
// 笔刷样式枚举
metaEnum
=
QMetaEnum
::
fromType
<
Qt
::
BrushStyle
>
();
for
(
int
i
=
0
;
i
<
metaEnum
.
keyCount
();
++
i
)
{
ui
->
com_brushStyle
->
addItem
(
metaEnum
.
key
(
i
),
metaEnum
.
value
(
i
));
}
ui
->
widget
->
installEventFilter
(
this
);
}
/**
* @brief 事件过滤器
* @param watched
* @param event
* @return
*/
bool
Widget
::
eventFilter
(
QObject
*
watched
,
QEvent
*
event
)
{
if
(
watched
==
ui
->
widget
&&
event
->
type
()
==
QEvent
::
Resize
)
{
ui
->
horizontalSlider_origin
->
setMaximum
(
ui
->
widget
->
width
());
ui
->
verticalSlider_origin
->
setMaximum
(
ui
->
widget
->
height
());
ui
->
horizontalSlider_origin
->
setValue
(
0
);
ui
->
verticalSlider_origin
->
setValue
(
ui
->
widget
->
height
());
}
return
QWidget
::
eventFilter
(
watched
,
event
);
}
/**
* @brief 水平偏移原点
* @param value
*/
void
Widget
::
on_horizontalSlider_origin_valueChanged
(
int
value
)
{
qDebug
()
<<
value
;
}
/**
* @brief 垂直偏移原点
* @param value
*/
void
Widget
::
on_verticalSlider_origin_valueChanged
(
int
value
)
{
qDebug
()
<<
ui
->
widget
->
height
()
-
value
;
}
/**
* @brief 旋转
* @param value
*/
void
Widget
::
on_horizontalSlider_rotate_valueChanged
(
int
value
)
{
qDebug
()
<<
value
;
}
void
Widget
::
on_checkBox_clicked
(
bool
checked
)
{
qDebug
()
<<
checked
;
}
PaintingDemo/basicdrawing/widget.h
浏览文件 @
6bbade06
...
...
@@ -18,6 +18,19 @@ public:
private:
void
init
();
protected:
bool
eventFilter
(
QObject
*
watched
,
QEvent
*
event
)
override
;
private
slots
:
void
on_horizontalSlider_origin_valueChanged
(
int
value
);
void
on_verticalSlider_origin_valueChanged
(
int
value
);
void
on_horizontalSlider_rotate_valueChanged
(
int
value
);
void
on_checkBox_clicked
(
bool
checked
);
private:
Ui
::
Widget
*
ui
;
};
...
...
PaintingDemo/basicdrawing/widget.ui
浏览文件 @
6bbade06
...
...
@@ -6,18 +6,15 @@
<rect>
<x>
0
</x>
<y>
0
</y>
<width>
800
</width>
<height>
6
00
</height>
<width>
946
</width>
<height>
6
99
</height>
</rect>
</property>
<property
name=
"windowTitle"
>
<string>
Widget
</string>
</property>
<layout
class=
"QGridLayout"
name=
"gridLayout"
>
<item
row=
"0"
column=
"0"
>
<widget
class=
"RenderArea"
name=
"widget"
native=
"true"
/>
</item>
<item
row=
"0"
column=
"1"
>
<item
row=
"0"
column=
"2"
rowspan=
"2"
>
<widget
class=
"QDockWidget"
name=
"dockWidget"
>
<property
name=
"sizePolicy"
>
<sizepolicy
hsizetype=
"Fixed"
vsizetype=
"Preferred"
>
...
...
@@ -27,7 +24,7 @@
</property>
<property
name=
"maximumSize"
>
<size>
<width>
2
5
0
</width>
<width>
2
7
0
</width>
<height>
524287
</height>
</size>
</property>
...
...
@@ -35,75 +32,60 @@
<layout
class=
"QGridLayout"
name=
"gridLayout_3"
>
<item
row=
"0"
column=
"0"
colspan=
"2"
>
<layout
class=
"QGridLayout"
name=
"gridLayout_2"
>
<item
row=
"0"
column=
"0"
>
<widget
class=
"QLabel"
name=
"label"
>
<property
name=
"text"
>
<string>
形状:
</string>
</property>
<property
name=
"alignment"
>
<set>
Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
</set>
<item
row=
"2"
column=
"1"
>
<widget
class=
"QComboBox"
name=
"com_penCapStyle"
>
<property
name=
"toolTip"
>
<string>
线条收头样式
</string>
</property>
</widget>
</item>
<item
row=
"0"
column=
"1"
>
<widget
class=
"QComboBox"
name=
"com_shape"
/>
</item>
<item
row=
"1"
column=
"0"
>
<widget
class=
"QLabel"
name=
"label_2"
>
<property
name=
"text"
>
<string>
画笔样式:
</string>
</property>
<property
name=
"alignment"
>
<set>
Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
</set>
<item
row=
"3"
column=
"1"
>
<widget
class=
"QComboBox"
name=
"com_penJoinStyle"
>
<property
name=
"toolTip"
>
<string>
线条连接样式
</string>
</property>
</widget>
</item>
<item
row=
"
1
"
column=
"1"
>
<widget
class=
"QComboBox"
name=
"com
boBox_2
"
/>
<item
row=
"
0
"
column=
"1"
>
<widget
class=
"QComboBox"
name=
"com
_shape
"
/>
</item>
<item
row=
"
2
"
column=
"0"
>
<widget
class=
"QLabel"
name=
"label_
4
"
>
<item
row=
"
3
"
column=
"0"
>
<widget
class=
"QLabel"
name=
"label_
5
"
>
<property
name=
"text"
>
<string>
笔帽
样式:
</string>
<string>
线条连接
样式:
</string>
</property>
<property
name=
"alignment"
>
<set>
Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
</set>
</property>
</widget>
</item>
<item
row=
"
2
"
column=
"1"
>
<widget
class=
"QComboBox"
name=
"com
boBox_3
"
/>
<item
row=
"
4
"
column=
"1"
>
<widget
class=
"QComboBox"
name=
"com
_brushStyle
"
/>
</item>
<item
row=
"
3
"
column=
"0"
>
<widget
class=
"QLabel"
name=
"label_
5
"
>
<item
row=
"
5
"
column=
"0"
>
<widget
class=
"QLabel"
name=
"label_
3
"
>
<property
name=
"text"
>
<string>
笔连接样式
:
</string>
<string>
画笔粗细
:
</string>
</property>
<property
name=
"alignment"
>
<set>
Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
</set>
</property>
</widget>
</item>
<item
row=
"3"
column=
"1"
>
<widget
class=
"QComboBox"
name=
"comboBox_4"
/>
</item>
<item
row=
"4"
column=
"0"
>
<widget
class=
"QLabel"
name=
"label_6"
>
<property
name=
"text"
>
<string>
笔刷样式:
</string>
<item
row=
"6"
column=
"1"
>
<widget
class=
"QSlider"
name=
"horizontalSlider_rotate"
>
<property
name=
"maximum"
>
<number>
360
</number>
</property>
<property
name=
"
alignment
"
>
<
set>
Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
</set
>
<property
name=
"
orientation
"
>
<
enum>
Qt::Horizontal
</enum
>
</property>
</widget>
</item>
<item
row=
"4"
column=
"1"
>
<widget
class=
"QComboBox"
name=
"comboBox_5"
/>
</item>
<item
row=
"5"
column=
"0"
>
<widget
class=
"QLabel"
name=
"label_3"
>
<item
row=
"1"
column=
"0"
>
<widget
class=
"QLabel"
name=
"label_2"
>
<property
name=
"text"
>
<string>
画笔
粗细
:
</string>
<string>
画笔
样式
:
</string>
</property>
<property
name=
"alignment"
>
<set>
Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
</set>
...
...
@@ -118,76 +100,58 @@
</widget>
</item>
<item
row=
"6"
column=
"0"
>
<widget
class=
"QLabel"
name=
"label_
8
"
>
<widget
class=
"QLabel"
name=
"label_
10
"
>
<property
name=
"text"
>
<string>
原点水平偏移
:
</string>
<string>
旋转
:
</string>
</property>
<property
name=
"alignment"
>
<set>
Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
</set>
</property>
</widget>
</item>
<item
row=
"6"
column=
"1"
>
<widget
class=
"QSlider"
name=
"horizontalSlider_2"
>
<property
name=
"orientation"
>
<enum>
Qt::Horizontal
</enum>
</property>
</widget>
</item>
<item
row=
"7"
column=
"0"
>
<widget
class=
"QLabel"
name=
"label_9"
>
<item
row=
"0"
column=
"0"
>
<widget
class=
"QLabel"
name=
"label"
>
<property
name=
"text"
>
<string>
原点垂直偏移
:
</string>
<string>
形状
:
</string>
</property>
<property
name=
"alignment"
>
<set>
Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
</set>
</property>
</widget>
</item>
<item
row=
"7"
column=
"1"
>
<widget
class=
"QSlider"
name=
"horizontalSlider_3"
>
<property
name=
"orientation"
>
<enum>
Qt::Horizontal
</enum>
</property>
</widget>
</item>
<item
row=
"8"
column=
"0"
>
<widget
class=
"QLabel"
name=
"label_7"
>
<item
row=
"4"
column=
"0"
>
<widget
class=
"QLabel"
name=
"label_6"
>
<property
name=
"text"
>
<string>
缩放
:
</string>
<string>
笔刷样式
:
</string>
</property>
<property
name=
"alignment"
>
<set>
Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
</set>
</property>
</widget>
</item>
<item
row=
"8"
column=
"1"
>
<widget
class=
"QSlider"
name=
"horizontalSlider"
>
<property
name=
"orientation"
>
<enum>
Qt::Horizontal
</enum>
</property>
</widget>
<item
row=
"1"
column=
"1"
>
<widget
class=
"QComboBox"
name=
"com_penStyle"
/>
</item>
<item
row=
"
9
"
column=
"0"
>
<widget
class=
"QLabel"
name=
"label_
10
"
>
<item
row=
"
2
"
column=
"0"
>
<widget
class=
"QLabel"
name=
"label_
4
"
>
<property
name=
"text"
>
<string>
旋转
:
</string>
<string>
笔帽样式
:
</string>
</property>
<property
name=
"alignment"
>
<set>
Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
</set>
</property>
</widget>
</item>
<item
row=
"
9
"
column=
"1"
>
<widget
class=
"Q
Slider"
name=
"horizontalSlider_4
"
>
<property
name=
"
orientation
"
>
<
enum>
Qt::Horizontal
</enum
>
<item
row=
"
7
"
column=
"1"
>
<widget
class=
"Q
CheckBox"
name=
"checkBox
"
>
<property
name=
"
text
"
>
<
string>
抗锯齿
</string
>
</property>
</widget>
</item>
</layout>
</item>
<item
row=
"
2
"
column=
"1"
>
<item
row=
"
3
"
column=
"1"
>
<spacer
name=
"verticalSpacer"
>
<property
name=
"orientation"
>
<enum>
Qt::Vertical
</enum>
...
...
@@ -200,17 +164,48 @@
</property>
</spacer>
</item>
<item
row=
"1"
column=
"0"
colspan=
"2"
>
<widget
class=
"QCheckBox"
name=
"checkBox"
>
<property
name=
"text"
>
<string>
抗锯齿
</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item
row=
"1"
column=
"1"
>
<widget
class=
"RenderArea"
name=
"widget"
native=
"true"
/>
</item>
<item
row=
"0"
column=
"1"
>
<widget
class=
"QSlider"
name=
"horizontalSlider_origin"
>
<property
name=
"toolTip"
>
<string>
原点水平偏移
</string>
</property>
<property
name=
"maximum"
>
<number>
700
</number>
</property>
<property
name=
"orientation"
>
<enum>
Qt::Horizontal
</enum>
</property>
<property
name=
"tickPosition"
>
<enum>
QSlider::TicksBelow
</enum>
</property>
</widget>
</item>
<item
row=
"1"
column=
"0"
>
<widget
class=
"QSlider"
name=
"verticalSlider_origin"
>
<property
name=
"toolTip"
>
<string>
原点垂直偏移
</string>
</property>
<property
name=
"maximum"
>
<number>
653
</number>
</property>
<property
name=
"value"
>
<number>
653
</number>
</property>
<property
name=
"orientation"
>
<enum>
Qt::Vertical
</enum>
</property>
<property
name=
"tickPosition"
>
<enum>
QSlider::TicksBelow
</enum>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录