Skip to content

Commit e12e4e3

Browse files
添加pinter相关代码
1 parent 66158e1 commit e12e4e3

File tree

7 files changed

+213
-14
lines changed

7 files changed

+213
-14
lines changed

qt_I18N/qt_I18N.pro.user

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE QtCreatorProject>
3-
<!-- Written by QtCreator 4.9.1, 2023-09-29T11:06:43. -->
3+
<!-- Written by QtCreator 4.9.1, 2023-09-29T12:01:34. -->
44
<qtcreator>
55
<data>
66
<variable>EnvironmentId</variable>
@@ -300,19 +300,19 @@
300300
</valuelist>
301301
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
302302
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
303-
<value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.Executable"></value>
304-
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Custom Executable</value>
303+
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">qt_I18N</value>
305304
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
306-
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
305+
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:/work/QT_examples/qt_I18N/qt_I18N.pro</value>
307306
<value type="QString" key="RunConfiguration.Arguments"></value>
308307
<value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
309308
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
310309
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
310+
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
311311
<value type="bool" key="RunConfiguration.UseMultiProcess">false</value>
312312
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
313313
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
314314
<value type="QString" key="RunConfiguration.WorkingDirectory"></value>
315-
<value type="QString" key="RunConfiguration.WorkingDirectory.default"></value>
315+
<value type="QString" key="RunConfiguration.WorkingDirectory.default">/work/QT_examples/build-qt_I18N-unknown-Debug</value>
316316
</valuemap>
317317
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
318318
</valuemap>

qt_painter/main.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include "mainwindow.h"
2+
#include <QApplication>
3+
4+
/*
5+
* 绘图主要依赖QPainter QPaintDevice QPaintEngine三个类
6+
* QPainter :用来执行绘图操作
7+
* QPaintDevice 提供绘图设备,是一个二维空间的抽象
8+
* QPaintEngine 提供在不同设备上绘图能力,处理创建自定义绘图类型一般用不到该类
9+
*
10+
* 这里主要说2D绘图的相关的知识
11+
*
12+
*
13+
*
14+
*/
15+
16+
17+
int main(int argc, char *argv[])
18+
{
19+
QApplication a(argc, argv);
20+
MainWindow w;
21+
w.show();
22+
23+
return a.exec();
24+
}

qt_painter/mainwindow.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include "mainwindow.h"
2+
#include "ui_mainwindow.h"
3+
#include <QPainter>
4+
#include <QToolTip>
5+
#include <QMouseEvent>
6+
#include <QTimer>
7+
MainWindow::MainWindow(QWidget *parent) :
8+
QMainWindow(parent),
9+
ui(new Ui::MainWindow)
10+
{
11+
ui->setupUi(this);
12+
13+
setMouseTracking(true);
14+
15+
QTimer *timer = new QTimer(this);
16+
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
17+
timer->start(1000);
18+
angle = 0;
19+
}
20+
21+
MainWindow::~MainWindow()
22+
{
23+
delete ui;
24+
}
25+
26+
27+
void MainWindow::paintEvent(QPaintEvent *)
28+
{
29+
angle += 10;
30+
if(angle == 360)
31+
angle = 0;
32+
int side = qMin(width(), height());
33+
QPainter painter(this);
34+
painter.setRenderHint(QPainter::Antialiasing);
35+
QTransform transform;
36+
transform.translate(width()/2, height()/2);
37+
transform.scale(side/300.0, side/300.0);
38+
transform.rotate(angle);
39+
painter.setWorldTransform(transform);
40+
painter.drawEllipse(-120, -120, 240, 240);
41+
painter.drawLine(0, 0, 100, 0);
42+
}
43+
44+
void MainWindow::mouseMoveEvent(QMouseEvent *event)
45+
{
46+
QString pos = QString("%1,%2").arg(event->pos().x()).arg(event->pos().y());
47+
QToolTip::showText(event->globalPos(), pos, this);
48+
}
49+

qt_painter/mainwindow.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef MAINWINDOW_H
2+
#define MAINWINDOW_H
3+
4+
#include <QMainWindow>
5+
6+
namespace Ui {
7+
class MainWindow;
8+
}
9+
10+
class MainWindow : public QMainWindow
11+
{
12+
Q_OBJECT
13+
14+
public:
15+
explicit MainWindow(QWidget *parent = nullptr);
16+
~MainWindow();
17+
18+
private:
19+
Ui::MainWindow *ui;
20+
QTimer *timer;
21+
int angle;
22+
23+
protected:
24+
void paintEvent(QPaintEvent *);
25+
void mouseMoveEvent(QMouseEvent *event);
26+
};
27+
28+
#endif // MAINWINDOW_H

qt_painter/mainwindow.ui

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<ui version="4.0">
2+
<class>MainWindow</class>
3+
<widget class="QMainWindow" name="MainWindow" >
4+
<property name="geometry" >
5+
<rect>
6+
<x>0</x>
7+
<y>0</y>
8+
<width>400</width>
9+
<height>300</height>
10+
</rect>
11+
</property>
12+
<property name="windowTitle" >
13+
<string>MainWindow</string>
14+
</property>
15+
<widget class="QMenuBar" name="menuBar" />
16+
<widget class="QToolBar" name="mainToolBar" />
17+
<widget class="QWidget" name="centralWidget" />
18+
<widget class="QStatusBar" name="statusBar" />
19+
</widget>
20+
<layoutDefault spacing="6" margin="11" />
21+
<pixmapfunction></pixmapfunction>
22+
<resources/>
23+
<connections/>
24+
</ui>

qt_painter/qt_painter.pro

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#-------------------------------------------------
2+
#
3+
# Project created by QtCreator 2023-09-30T09:11:13
4+
#
5+
#-------------------------------------------------
6+
7+
QT += core gui
8+
9+
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
10+
11+
TARGET = qt_painter
12+
TEMPLATE = app
13+
14+
# The following define makes your compiler emit warnings if you use
15+
# any feature of Qt which has been marked as deprecated (the exact warnings
16+
# depend on your compiler). Please consult the documentation of the
17+
# deprecated API in order to know how to port your code away from it.
18+
DEFINES += QT_DEPRECATED_WARNINGS
19+
20+
# You can also make your code fail to compile if you use deprecated APIs.
21+
# In order to do so, uncomment the following line.
22+
# You can also select to disable deprecated APIs only up to a certain version of Qt.
23+
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
24+
25+
CONFIG += c++11
26+
27+
SOURCES += \
28+
main.cpp \
29+
mainwindow.cpp
30+
31+
HEADERS += \
32+
mainwindow.h
33+
34+
FORMS += \
35+
mainwindow.ui
36+
37+
# Default rules for deployment.
38+
qnx: target.path = /tmp/$${TARGET}/bin
39+
else: unix:!android: target.path = /opt/$${TARGET}/bin
40+
!isEmpty(target.path): INSTALLS += target

qt_whatisit/mainwindow.ui

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,58 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
12
<ui version="4.0">
23
<class>MainWindow</class>
3-
<widget class="QMainWindow" name="MainWindow" >
4-
<property name="geometry" >
4+
<widget class="QMainWindow" name="MainWindow">
5+
<property name="geometry">
56
<rect>
67
<x>0</x>
78
<y>0</y>
89
<width>400</width>
910
<height>300</height>
1011
</rect>
1112
</property>
12-
<property name="windowTitle" >
13+
<property name="windowTitle">
1314
<string>MainWindow</string>
1415
</property>
15-
<widget class="QMenuBar" name="menuBar" />
16-
<widget class="QToolBar" name="mainToolBar" />
17-
<widget class="QWidget" name="centralWidget" />
18-
<widget class="QStatusBar" name="statusBar" />
16+
<widget class="QWidget" name="centralWidget"/>
17+
<widget class="QMenuBar" name="menuBar">
18+
<property name="geometry">
19+
<rect>
20+
<x>0</x>
21+
<y>0</y>
22+
<width>400</width>
23+
<height>28</height>
24+
</rect>
25+
</property>
26+
<widget class="QMenu" name="menu_File">
27+
<property name="title">
28+
<string>&amp;File</string>
29+
</property>
30+
<addaction name="actionNew"/>
31+
<addaction name="actionOPen"/>
32+
</widget>
33+
<addaction name="menu_File"/>
34+
</widget>
35+
<widget class="QToolBar" name="mainToolBar">
36+
<attribute name="toolBarArea">
37+
<enum>TopToolBarArea</enum>
38+
</attribute>
39+
<attribute name="toolBarBreak">
40+
<bool>false</bool>
41+
</attribute>
42+
</widget>
43+
<widget class="QStatusBar" name="statusBar"/>
44+
<action name="actionNew">
45+
<property name="text">
46+
<string>New</string>
47+
</property>
48+
</action>
49+
<action name="actionOPen">
50+
<property name="text">
51+
<string>OPen</string>
52+
</property>
53+
</action>
1954
</widget>
20-
<layoutDefault spacing="6" margin="11" />
21-
<pixmapfunction></pixmapfunction>
55+
<layoutdefault spacing="6" margin="11"/>
2256
<resources/>
2357
<connections/>
2458
</ui>

0 commit comments

Comments
 (0)