Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3#include <QApplication>
4#include <QtMath>
5#include <QPainter>
6#include <QVBoxLayout>
7#include <QWidget>
8
9
11{
12 void paintEvent(QPaintEvent *) override;
13};
14
17{
18 QPainter painter(this);
20 painter.drawRect(0, 0, 100, 100);
21
22 painter.rotate(45);
23
24 painter.setFont(QFont("Helvetica", 24));
26 painter.drawText(20, 10, "QTransform");
27}
29
31{
32 void paintEvent(QPaintEvent *) override;
33};
34
37{
38 QPainter painter(this);
40 painter.drawRect(0, 0, 100, 100);
41
43 transform.translate(50, 50);
44 transform.rotate(45);
45 transform.scale(0.5, 1.0);
47
48 painter.setFont(QFont("Helvetica", 24));
50 painter.drawText(20, 10, "QTransform");
51}
53
55{
56 void paintEvent(QPaintEvent *) override;
57};
58
61{
62 const double a = qDegreesToRadians(45.0);
63 double sina = sin(a);
64 double cosa = cos(a);
65
66 QTransform scale(0.5, 0, 0, 1.0, 0, 0);
67 QTransform rotate(cosa, sina, -sina, cosa, 0, 0);
68 QTransform translate(1, 0, 0, 1, 50.0, 50.0);
69
71
72 QPainter painter(this);
74 painter.drawRect(0, 0, 100, 100);
75
77
78 painter.setFont(QFont("Helvetica", 24));
80 painter.drawText(20, 10, "QTransform");
81}
83
84int main(int argc, char **argv)
85{
86 QApplication app(argc, argv);
87
89
92 BasicOperations *basicWidget = new BasicOperations;
93
95 layout->addWidget(simpleWidget);
96 layout->addWidget(combinedWidget);
97 layout->addWidget(basicWidget);
98
99 widget.show();
100 widget.resize(130, 350);
101 return app.exec();
102}
void paintEvent(QPaintEvent *) override
[2]
Definition main.cpp:60
void paintEvent(QPaintEvent *) override
[1]
Definition main.cpp:36
The QApplication class manages the GUI application's control flow and main settings.
static int exec()
Enters the main event loop and waits until exit() is called, then returns the value that was set to e...
void addWidget(QWidget *, int stretch=0, Qt::Alignment alignment=Qt::Alignment())
Adds widget to the end of this box layout, with a stretch factor of stretch and alignment alignment.
\reentrant
Definition qfont.h:22
The QPaintEvent class contains event parameters for paint events.
Definition qevent.h:486
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
void drawRect(const QRectF &rect)
Draws the current rectangle with the current pen and brush.
Definition qpainter.h:519
void setPen(const QColor &color)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void rotate(qreal a)
Rotates the coordinate system clockwise.
void setFont(const QFont &f)
Sets the painter's font to the given font.
void drawText(const QPointF &p, const QString &s)
Draws the given text with the currently defined text direction, beginning at the given position.
void setTransform(const QTransform &transform, bool combine=false)
\inmodule QtGui
Definition qpen.h:28
The QTransform class specifies 2D transformations of a coordinate system.
Definition qtransform.h:20
QTransform & rotate(qreal a, Qt::Axis axis=Qt::ZAxis, qreal distanceToPlane=1024.0f)
QTransform & scale(qreal sx, qreal sy)
Scales the coordinate system by sx horizontally and sy vertically, and returns a reference to the mat...
QTransform & translate(qreal dx, qreal dy)
Moves the coordinate system dx along the x axis and dy along the y axis, and returns a reference to t...
The QVBoxLayout class lines up widgets vertically.
Definition qboxlayout.h:91
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
void show()
Shows the widget and its child widgets.
Definition qwidget.cpp:7875
void resize(int w, int h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qwidget.h:883
void paintEvent(QPaintEvent *) override
[0]
Definition main.cpp:16
QOpenGLWidget * widget
[1]
int main()
[0]
@ blue
Definition qnamespace.h:37
@ black
Definition qnamespace.h:30
@ DashLine
constexpr float qDegreesToRadians(float degrees)
Definition qmath.h:260
GLboolean GLboolean GLboolean GLboolean a
[7]
GLuint GLenum GLenum transform
GLenum GLenum GLenum GLenum GLenum scale
static bool translate(xcb_connection_t *connection, xcb_window_t child, xcb_window_t parent, int *x, int *y)
QVBoxLayout * layout
QApplication app(argc, argv)
[0]
QPainter painter(this)
[7]