mirror of
https://github.com/crystalidea/qt6windows7.git
synced 2025-07-04 00:05:25 +08:00
qt 6.5.1 original
This commit is contained in:
51
examples/widgets/painting/basicdrawing/CMakeLists.txt
Normal file
51
examples/widgets/painting/basicdrawing/CMakeLists.txt
Normal file
@ -0,0 +1,51 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(basicdrawing LANGUAGES CXX)
|
||||
|
||||
if(NOT DEFINED INSTALL_EXAMPLESDIR)
|
||||
set(INSTALL_EXAMPLESDIR "examples")
|
||||
endif()
|
||||
|
||||
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/painting/basicdrawing")
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
|
||||
|
||||
qt_standard_project_setup()
|
||||
|
||||
qt_add_executable(basicdrawing
|
||||
main.cpp
|
||||
renderarea.cpp renderarea.h
|
||||
window.cpp window.h
|
||||
)
|
||||
|
||||
set_target_properties(basicdrawing PROPERTIES
|
||||
WIN32_EXECUTABLE TRUE
|
||||
MACOSX_BUNDLE TRUE
|
||||
)
|
||||
|
||||
target_link_libraries(basicdrawing PRIVATE
|
||||
Qt6::Core
|
||||
Qt6::Gui
|
||||
Qt6::Widgets
|
||||
)
|
||||
|
||||
# Resources:
|
||||
set(basicdrawing_resource_files
|
||||
"images/brick.png"
|
||||
"images/qt-logo.png"
|
||||
)
|
||||
|
||||
qt_add_resources(basicdrawing "basicdrawing"
|
||||
PREFIX
|
||||
"/"
|
||||
FILES
|
||||
${basicdrawing_resource_files}
|
||||
)
|
||||
|
||||
install(TARGETS basicdrawing
|
||||
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
)
|
13
examples/widgets/painting/basicdrawing/basicdrawing.pro
Normal file
13
examples/widgets/painting/basicdrawing/basicdrawing.pro
Normal file
@ -0,0 +1,13 @@
|
||||
QT += widgets
|
||||
requires(qtConfig(combobox))
|
||||
|
||||
HEADERS = renderarea.h \
|
||||
window.h
|
||||
SOURCES = main.cpp \
|
||||
renderarea.cpp \
|
||||
window.cpp
|
||||
RESOURCES = basicdrawing.qrc
|
||||
|
||||
# install
|
||||
target.path = $$[QT_INSTALL_EXAMPLES]/widgets/painting/basicdrawing
|
||||
INSTALLS += target
|
6
examples/widgets/painting/basicdrawing/basicdrawing.qrc
Normal file
6
examples/widgets/painting/basicdrawing/basicdrawing.qrc
Normal file
@ -0,0 +1,6 @@
|
||||
<!DOCTYPE RCC><RCC version="1.0">
|
||||
<qresource>
|
||||
<file>images/brick.png</file>
|
||||
<file>images/qt-logo.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
BIN
examples/widgets/painting/basicdrawing/images/brick.png
Normal file
BIN
examples/widgets/painting/basicdrawing/images/brick.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 767 B |
BIN
examples/widgets/painting/basicdrawing/images/qt-logo.png
Normal file
BIN
examples/widgets/painting/basicdrawing/images/qt-logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
16
examples/widgets/painting/basicdrawing/main.cpp
Normal file
16
examples/widgets/painting/basicdrawing/main.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#include "window.h"
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
Q_INIT_RESOURCE(basicdrawing);
|
||||
|
||||
QApplication app(argc, argv);
|
||||
Window window;
|
||||
window.show();
|
||||
return app.exec();
|
||||
}
|
173
examples/widgets/painting/basicdrawing/renderarea.cpp
Normal file
173
examples/widgets/painting/basicdrawing/renderarea.cpp
Normal file
@ -0,0 +1,173 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#include "renderarea.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QPainterPath>
|
||||
|
||||
//! [0]
|
||||
RenderArea::RenderArea(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
shape = Polygon;
|
||||
antialiased = false;
|
||||
transformed = false;
|
||||
pixmap.load(":/images/qt-logo.png");
|
||||
|
||||
setBackgroundRole(QPalette::Base);
|
||||
setAutoFillBackground(true);
|
||||
}
|
||||
//! [0]
|
||||
|
||||
//! [1]
|
||||
QSize RenderArea::minimumSizeHint() const
|
||||
{
|
||||
return QSize(100, 100);
|
||||
}
|
||||
//! [1]
|
||||
|
||||
//! [2]
|
||||
QSize RenderArea::sizeHint() const
|
||||
{
|
||||
return QSize(400, 200);
|
||||
}
|
||||
//! [2]
|
||||
|
||||
//! [3]
|
||||
void RenderArea::setShape(Shape shape)
|
||||
{
|
||||
this->shape = shape;
|
||||
update();
|
||||
}
|
||||
//! [3]
|
||||
|
||||
//! [4]
|
||||
void RenderArea::setPen(const QPen &pen)
|
||||
{
|
||||
this->pen = pen;
|
||||
update();
|
||||
}
|
||||
//! [4]
|
||||
|
||||
//! [5]
|
||||
void RenderArea::setBrush(const QBrush &brush)
|
||||
{
|
||||
this->brush = brush;
|
||||
update();
|
||||
}
|
||||
//! [5]
|
||||
|
||||
//! [6]
|
||||
void RenderArea::setAntialiased(bool antialiased)
|
||||
{
|
||||
this->antialiased = antialiased;
|
||||
update();
|
||||
}
|
||||
//! [6]
|
||||
|
||||
//! [7]
|
||||
void RenderArea::setTransformed(bool transformed)
|
||||
{
|
||||
this->transformed = transformed;
|
||||
update();
|
||||
}
|
||||
//! [7]
|
||||
|
||||
//! [8]
|
||||
void RenderArea::paintEvent(QPaintEvent * /* event */)
|
||||
{
|
||||
static const QPoint points[4] = {
|
||||
QPoint(10, 80),
|
||||
QPoint(20, 10),
|
||||
QPoint(80, 30),
|
||||
QPoint(90, 70)
|
||||
};
|
||||
|
||||
QRect rect(10, 20, 80, 60);
|
||||
|
||||
QPainterPath path;
|
||||
path.moveTo(20, 80);
|
||||
path.lineTo(20, 30);
|
||||
path.cubicTo(80, 0, 50, 50, 80, 80);
|
||||
|
||||
int startAngle = 20 * 16;
|
||||
int arcLength = 120 * 16;
|
||||
//! [8]
|
||||
|
||||
//! [9]
|
||||
QPainter painter(this);
|
||||
painter.setPen(pen);
|
||||
painter.setBrush(brush);
|
||||
if (antialiased)
|
||||
painter.setRenderHint(QPainter::Antialiasing, true);
|
||||
//! [9]
|
||||
|
||||
//! [10]
|
||||
for (int x = 0; x < width(); x += 100) {
|
||||
for (int y = 0; y < height(); y += 100) {
|
||||
painter.save();
|
||||
painter.translate(x, y);
|
||||
//! [10] //! [11]
|
||||
if (transformed) {
|
||||
painter.translate(50, 50);
|
||||
painter.rotate(60.0);
|
||||
painter.scale(0.6, 0.9);
|
||||
painter.translate(-50, -50);
|
||||
}
|
||||
//! [11]
|
||||
|
||||
//! [12]
|
||||
switch (shape) {
|
||||
case Line:
|
||||
painter.drawLine(rect.bottomLeft(), rect.topRight());
|
||||
break;
|
||||
case Points:
|
||||
painter.drawPoints(points, 4);
|
||||
break;
|
||||
case Polyline:
|
||||
painter.drawPolyline(points, 4);
|
||||
break;
|
||||
case Polygon:
|
||||
painter.drawPolygon(points, 4);
|
||||
break;
|
||||
case Rect:
|
||||
painter.drawRect(rect);
|
||||
break;
|
||||
case RoundedRect:
|
||||
painter.drawRoundedRect(rect, 25, 25, Qt::RelativeSize);
|
||||
break;
|
||||
case Ellipse:
|
||||
painter.drawEllipse(rect);
|
||||
break;
|
||||
case Arc:
|
||||
painter.drawArc(rect, startAngle, arcLength);
|
||||
break;
|
||||
case Chord:
|
||||
painter.drawChord(rect, startAngle, arcLength);
|
||||
break;
|
||||
case Pie:
|
||||
painter.drawPie(rect, startAngle, arcLength);
|
||||
break;
|
||||
case Path:
|
||||
painter.drawPath(path);
|
||||
break;
|
||||
case Text:
|
||||
painter.drawText(rect,
|
||||
Qt::AlignCenter,
|
||||
tr("Qt by\nThe Qt Company"));
|
||||
break;
|
||||
case Pixmap:
|
||||
painter.drawPixmap(10, 10, pixmap);
|
||||
}
|
||||
//! [12] //! [13]
|
||||
painter.restore();
|
||||
}
|
||||
}
|
||||
|
||||
painter.setRenderHint(QPainter::Antialiasing, false);
|
||||
painter.setPen(palette().dark().color());
|
||||
painter.setBrush(Qt::NoBrush);
|
||||
painter.drawRect(QRect(0, 0, width() - 1, height() - 1));
|
||||
}
|
||||
//! [13]
|
46
examples/widgets/painting/basicdrawing/renderarea.h
Normal file
46
examples/widgets/painting/basicdrawing/renderarea.h
Normal file
@ -0,0 +1,46 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#ifndef RENDERAREA_H
|
||||
#define RENDERAREA_H
|
||||
|
||||
#include <QBrush>
|
||||
#include <QPen>
|
||||
#include <QPixmap>
|
||||
#include <QWidget>
|
||||
|
||||
//! [0]
|
||||
class RenderArea : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum Shape { Line, Points, Polyline, Polygon, Rect, RoundedRect, Ellipse, Arc,
|
||||
Chord, Pie, Path, Text, Pixmap };
|
||||
|
||||
explicit RenderArea(QWidget *parent = nullptr);
|
||||
|
||||
QSize minimumSizeHint() const override;
|
||||
QSize sizeHint() const override;
|
||||
|
||||
public slots:
|
||||
void setShape(Shape shape);
|
||||
void setPen(const QPen &pen);
|
||||
void setBrush(const QBrush &brush);
|
||||
void setAntialiased(bool antialiased);
|
||||
void setTransformed(bool transformed);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
|
||||
private:
|
||||
Shape shape;
|
||||
QPen pen;
|
||||
QBrush brush;
|
||||
bool antialiased;
|
||||
bool transformed;
|
||||
QPixmap pixmap;
|
||||
};
|
||||
//! [0]
|
||||
|
||||
#endif // RENDERAREA_H
|
222
examples/widgets/painting/basicdrawing/window.cpp
Normal file
222
examples/widgets/painting/basicdrawing/window.cpp
Normal file
@ -0,0 +1,222 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#include "renderarea.h"
|
||||
#include "window.h"
|
||||
|
||||
#include <QtWidgets>
|
||||
|
||||
//! [0]
|
||||
const int IdRole = Qt::UserRole;
|
||||
//! [0]
|
||||
|
||||
//! [1]
|
||||
Window::Window()
|
||||
{
|
||||
renderArea = new RenderArea;
|
||||
|
||||
shapeComboBox = new QComboBox;
|
||||
shapeComboBox->addItem(tr("Polygon"), RenderArea::Polygon);
|
||||
shapeComboBox->addItem(tr("Rectangle"), RenderArea::Rect);
|
||||
shapeComboBox->addItem(tr("Rounded Rectangle"), RenderArea::RoundedRect);
|
||||
shapeComboBox->addItem(tr("Ellipse"), RenderArea::Ellipse);
|
||||
shapeComboBox->addItem(tr("Pie"), RenderArea::Pie);
|
||||
shapeComboBox->addItem(tr("Chord"), RenderArea::Chord);
|
||||
shapeComboBox->addItem(tr("Path"), RenderArea::Path);
|
||||
shapeComboBox->addItem(tr("Line"), RenderArea::Line);
|
||||
shapeComboBox->addItem(tr("Polyline"), RenderArea::Polyline);
|
||||
shapeComboBox->addItem(tr("Arc"), RenderArea::Arc);
|
||||
shapeComboBox->addItem(tr("Points"), RenderArea::Points);
|
||||
shapeComboBox->addItem(tr("Text"), RenderArea::Text);
|
||||
shapeComboBox->addItem(tr("Pixmap"), RenderArea::Pixmap);
|
||||
|
||||
shapeLabel = new QLabel(tr("&Shape:"));
|
||||
shapeLabel->setBuddy(shapeComboBox);
|
||||
//! [1]
|
||||
|
||||
//! [2]
|
||||
penWidthSpinBox = new QSpinBox;
|
||||
penWidthSpinBox->setRange(0, 20);
|
||||
penWidthSpinBox->setSpecialValueText(tr("0 (cosmetic pen)"));
|
||||
|
||||
penWidthLabel = new QLabel(tr("Pen &Width:"));
|
||||
penWidthLabel->setBuddy(penWidthSpinBox);
|
||||
//! [2]
|
||||
|
||||
//! [3]
|
||||
penStyleComboBox = new QComboBox;
|
||||
penStyleComboBox->addItem(tr("Solid"), static_cast<int>(Qt::SolidLine));
|
||||
penStyleComboBox->addItem(tr("Dash"), static_cast<int>(Qt::DashLine));
|
||||
penStyleComboBox->addItem(tr("Dot"), static_cast<int>(Qt::DotLine));
|
||||
penStyleComboBox->addItem(tr("Dash Dot"), static_cast<int>(Qt::DashDotLine));
|
||||
penStyleComboBox->addItem(tr("Dash Dot Dot"), static_cast<int>(Qt::DashDotDotLine));
|
||||
penStyleComboBox->addItem(tr("None"), static_cast<int>(Qt::NoPen));
|
||||
|
||||
penStyleLabel = new QLabel(tr("&Pen Style:"));
|
||||
penStyleLabel->setBuddy(penStyleComboBox);
|
||||
|
||||
penCapComboBox = new QComboBox;
|
||||
penCapComboBox->addItem(tr("Flat"), Qt::FlatCap);
|
||||
penCapComboBox->addItem(tr("Square"), Qt::SquareCap);
|
||||
penCapComboBox->addItem(tr("Round"), Qt::RoundCap);
|
||||
|
||||
penCapLabel = new QLabel(tr("Pen &Cap:"));
|
||||
penCapLabel->setBuddy(penCapComboBox);
|
||||
|
||||
penJoinComboBox = new QComboBox;
|
||||
penJoinComboBox->addItem(tr("Miter"), Qt::MiterJoin);
|
||||
penJoinComboBox->addItem(tr("Bevel"), Qt::BevelJoin);
|
||||
penJoinComboBox->addItem(tr("Round"), Qt::RoundJoin);
|
||||
|
||||
penJoinLabel = new QLabel(tr("Pen &Join:"));
|
||||
penJoinLabel->setBuddy(penJoinComboBox);
|
||||
//! [3]
|
||||
|
||||
//! [4]
|
||||
brushStyleComboBox = new QComboBox;
|
||||
brushStyleComboBox->addItem(tr("Linear Gradient"),
|
||||
static_cast<int>(Qt::LinearGradientPattern));
|
||||
brushStyleComboBox->addItem(tr("Radial Gradient"),
|
||||
static_cast<int>(Qt::RadialGradientPattern));
|
||||
brushStyleComboBox->addItem(tr("Conical Gradient"),
|
||||
static_cast<int>(Qt::ConicalGradientPattern));
|
||||
brushStyleComboBox->addItem(tr("Texture"), static_cast<int>(Qt::TexturePattern));
|
||||
brushStyleComboBox->addItem(tr("Solid"), static_cast<int>(Qt::SolidPattern));
|
||||
brushStyleComboBox->addItem(tr("Horizontal"), static_cast<int>(Qt::HorPattern));
|
||||
brushStyleComboBox->addItem(tr("Vertical"), static_cast<int>(Qt::VerPattern));
|
||||
brushStyleComboBox->addItem(tr("Cross"), static_cast<int>(Qt::CrossPattern));
|
||||
brushStyleComboBox->addItem(tr("Backward Diagonal"), static_cast<int>(Qt::BDiagPattern));
|
||||
brushStyleComboBox->addItem(tr("Forward Diagonal"), static_cast<int>(Qt::FDiagPattern));
|
||||
brushStyleComboBox->addItem(tr("Diagonal Cross"), static_cast<int>(Qt::DiagCrossPattern));
|
||||
brushStyleComboBox->addItem(tr("Dense 1"), static_cast<int>(Qt::Dense1Pattern));
|
||||
brushStyleComboBox->addItem(tr("Dense 2"), static_cast<int>(Qt::Dense2Pattern));
|
||||
brushStyleComboBox->addItem(tr("Dense 3"), static_cast<int>(Qt::Dense3Pattern));
|
||||
brushStyleComboBox->addItem(tr("Dense 4"), static_cast<int>(Qt::Dense4Pattern));
|
||||
brushStyleComboBox->addItem(tr("Dense 5"), static_cast<int>(Qt::Dense5Pattern));
|
||||
brushStyleComboBox->addItem(tr("Dense 6"), static_cast<int>(Qt::Dense6Pattern));
|
||||
brushStyleComboBox->addItem(tr("Dense 7"), static_cast<int>(Qt::Dense7Pattern));
|
||||
brushStyleComboBox->addItem(tr("None"), static_cast<int>(Qt::NoBrush));
|
||||
|
||||
brushStyleLabel = new QLabel(tr("&Brush:"));
|
||||
brushStyleLabel->setBuddy(brushStyleComboBox);
|
||||
//! [4]
|
||||
|
||||
//! [5]
|
||||
otherOptionsLabel = new QLabel(tr("Options:"));
|
||||
//! [5] //! [6]
|
||||
antialiasingCheckBox = new QCheckBox(tr("&Antialiasing"));
|
||||
//! [6] //! [7]
|
||||
transformationsCheckBox = new QCheckBox(tr("&Transformations"));
|
||||
//! [7]
|
||||
|
||||
//! [8]
|
||||
connect(shapeComboBox, &QComboBox::activated,
|
||||
this, &Window::shapeChanged);
|
||||
connect(penWidthSpinBox, &QSpinBox::valueChanged,
|
||||
this, &Window::penChanged);
|
||||
connect(penStyleComboBox, &QComboBox::activated,
|
||||
this, &Window::penChanged);
|
||||
connect(penCapComboBox, &QComboBox::activated,
|
||||
this, &Window::penChanged);
|
||||
connect(penJoinComboBox, &QComboBox::activated,
|
||||
this, &Window::penChanged);
|
||||
connect(brushStyleComboBox, &QComboBox::activated,
|
||||
this, &Window::brushChanged);
|
||||
connect(antialiasingCheckBox, &QAbstractButton::toggled,
|
||||
renderArea, &RenderArea::setAntialiased);
|
||||
connect(transformationsCheckBox, &QAbstractButton::toggled,
|
||||
renderArea, &RenderArea::setTransformed);
|
||||
//! [8]
|
||||
|
||||
//! [9]
|
||||
QGridLayout *mainLayout = new QGridLayout;
|
||||
//! [9] //! [10]
|
||||
mainLayout->setColumnStretch(0, 1);
|
||||
mainLayout->setColumnStretch(3, 1);
|
||||
mainLayout->addWidget(renderArea, 0, 0, 1, 4);
|
||||
mainLayout->addWidget(shapeLabel, 2, 0, Qt::AlignRight);
|
||||
mainLayout->addWidget(shapeComboBox, 2, 1);
|
||||
mainLayout->addWidget(penWidthLabel, 3, 0, Qt::AlignRight);
|
||||
mainLayout->addWidget(penWidthSpinBox, 3, 1);
|
||||
mainLayout->addWidget(penStyleLabel, 4, 0, Qt::AlignRight);
|
||||
mainLayout->addWidget(penStyleComboBox, 4, 1);
|
||||
mainLayout->addWidget(penCapLabel, 3, 2, Qt::AlignRight);
|
||||
mainLayout->addWidget(penCapComboBox, 3, 3);
|
||||
mainLayout->addWidget(penJoinLabel, 2, 2, Qt::AlignRight);
|
||||
mainLayout->addWidget(penJoinComboBox, 2, 3);
|
||||
mainLayout->addWidget(brushStyleLabel, 4, 2, Qt::AlignRight);
|
||||
mainLayout->addWidget(brushStyleComboBox, 4, 3);
|
||||
mainLayout->addWidget(otherOptionsLabel, 5, 0, Qt::AlignRight);
|
||||
mainLayout->addWidget(antialiasingCheckBox, 5, 1, 1, 1, Qt::AlignRight);
|
||||
mainLayout->addWidget(transformationsCheckBox, 5, 2, 1, 2, Qt::AlignRight);
|
||||
setLayout(mainLayout);
|
||||
|
||||
shapeChanged();
|
||||
penChanged();
|
||||
brushChanged();
|
||||
antialiasingCheckBox->setChecked(true);
|
||||
|
||||
setWindowTitle(tr("Basic Drawing"));
|
||||
}
|
||||
//! [10]
|
||||
|
||||
//! [11]
|
||||
void Window::shapeChanged()
|
||||
{
|
||||
RenderArea::Shape shape = RenderArea::Shape(shapeComboBox->itemData(
|
||||
shapeComboBox->currentIndex(), IdRole).toInt());
|
||||
renderArea->setShape(shape);
|
||||
}
|
||||
//! [11]
|
||||
|
||||
//! [12]
|
||||
void Window::penChanged()
|
||||
{
|
||||
int width = penWidthSpinBox->value();
|
||||
Qt::PenStyle style = Qt::PenStyle(penStyleComboBox->itemData(
|
||||
penStyleComboBox->currentIndex(), IdRole).toInt());
|
||||
Qt::PenCapStyle cap = Qt::PenCapStyle(penCapComboBox->itemData(
|
||||
penCapComboBox->currentIndex(), IdRole).toInt());
|
||||
Qt::PenJoinStyle join = Qt::PenJoinStyle(penJoinComboBox->itemData(
|
||||
penJoinComboBox->currentIndex(), IdRole).toInt());
|
||||
|
||||
renderArea->setPen(QPen(Qt::blue, width, style, cap, join));
|
||||
}
|
||||
//! [12]
|
||||
|
||||
//! [13]
|
||||
void Window::brushChanged()
|
||||
{
|
||||
Qt::BrushStyle style = Qt::BrushStyle(brushStyleComboBox->itemData(
|
||||
//! [13]
|
||||
brushStyleComboBox->currentIndex(), IdRole).toInt());
|
||||
|
||||
//! [14]
|
||||
if (style == Qt::LinearGradientPattern) {
|
||||
QLinearGradient linearGradient(0, 0, 100, 100);
|
||||
linearGradient.setColorAt(0.0, Qt::white);
|
||||
linearGradient.setColorAt(0.2, Qt::green);
|
||||
linearGradient.setColorAt(1.0, Qt::black);
|
||||
renderArea->setBrush(linearGradient);
|
||||
//! [14] //! [15]
|
||||
} else if (style == Qt::RadialGradientPattern) {
|
||||
QRadialGradient radialGradient(50, 50, 50, 70, 70);
|
||||
radialGradient.setColorAt(0.0, Qt::white);
|
||||
radialGradient.setColorAt(0.2, Qt::green);
|
||||
radialGradient.setColorAt(1.0, Qt::black);
|
||||
renderArea->setBrush(radialGradient);
|
||||
} else if (style == Qt::ConicalGradientPattern) {
|
||||
QConicalGradient conicalGradient(50, 50, 150);
|
||||
conicalGradient.setColorAt(0.0, Qt::white);
|
||||
conicalGradient.setColorAt(0.2, Qt::green);
|
||||
conicalGradient.setColorAt(1.0, Qt::black);
|
||||
renderArea->setBrush(conicalGradient);
|
||||
//! [15] //! [16]
|
||||
} else if (style == Qt::TexturePattern) {
|
||||
renderArea->setBrush(QBrush(QPixmap(":/images/brick.png")));
|
||||
//! [16] //! [17]
|
||||
} else {
|
||||
renderArea->setBrush(QBrush(Qt::green, style));
|
||||
}
|
||||
}
|
||||
//! [17]
|
50
examples/widgets/painting/basicdrawing/window.h
Normal file
50
examples/widgets/painting/basicdrawing/window.h
Normal file
@ -0,0 +1,50 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#ifndef WINDOW_H
|
||||
#define WINDOW_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QCheckBox;
|
||||
class QComboBox;
|
||||
class QLabel;
|
||||
class QSpinBox;
|
||||
QT_END_NAMESPACE
|
||||
class RenderArea;
|
||||
|
||||
//! [0]
|
||||
class Window : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Window();
|
||||
|
||||
private slots:
|
||||
void shapeChanged();
|
||||
void penChanged();
|
||||
void brushChanged();
|
||||
|
||||
private:
|
||||
RenderArea *renderArea;
|
||||
QLabel *shapeLabel;
|
||||
QLabel *penWidthLabel;
|
||||
QLabel *penStyleLabel;
|
||||
QLabel *penCapLabel;
|
||||
QLabel *penJoinLabel;
|
||||
QLabel *brushStyleLabel;
|
||||
QLabel *otherOptionsLabel;
|
||||
QComboBox *shapeComboBox;
|
||||
QSpinBox *penWidthSpinBox;
|
||||
QComboBox *penStyleComboBox;
|
||||
QComboBox *penCapComboBox;
|
||||
QComboBox *penJoinComboBox;
|
||||
QComboBox *brushStyleComboBox;
|
||||
QCheckBox *antialiasingCheckBox;
|
||||
QCheckBox *transformationsCheckBox;
|
||||
};
|
||||
//! [0]
|
||||
|
||||
#endif // WINDOW_H
|
Reference in New Issue
Block a user