이 페이지에서

QCanvasPath Class

QCanvasPath는 QCanvasPainter 의 기본 경로 형식입니다... .

헤더: #include <QCanvasPath>
CMake: find_package(Qt6 REQUIRED COMPONENTS CanvasPainter)
target_link_libraries(mytarget PRIVATE Qt6::CanvasPainter)
이후 Qt 6.11
상태: 기술 미리보기

공용 함수

QCanvasPath()
QCanvasPath(qsizetype commandsSize, qsizetype commandsDataSize = -1)
QCanvasPath(const QCanvasPath &path)
QCanvasPath(QCanvasPath &&other)
~QCanvasPath()
void addPath(const QCanvasPath &path, const QTransform &transform = QTransform())
void addPath(const QCanvasPath &path, qsizetype start, qsizetype count, const QTransform &transform = QTransform())
void arc(float centerX, float centerY, float radius, float a0, float a1, QCanvasPainter::PathWinding direction = QCanvasPainter::PathWinding::ClockWise, QCanvasPainter::PathConnection connection = QCanvasPainter::PathConnection::Connected)
void arc(QPointF centerPoint, float radius, float a0, float a1, QCanvasPainter::PathWinding direction = QCanvasPainter::PathWinding::ClockWise, QCanvasPainter::PathConnection connection = QCanvasPainter::PathConnection::Connected)
void arcTo(float x1, float y1, float x2, float y2, float radius)
void arcTo(QPointF point1, QPointF point2, float radius)
void beginHoleSubPath()
void beginSolidSubPath()
void bezierCurveTo(float cp1X, float cp1Y, float cp2X, float cp2Y, float x, float y)
void bezierCurveTo(QPointF controlPoint1, QPointF controlPoint2, QPointF endPoint)
void circle(float x, float y, float radius)
void circle(QPointF centerPoint, float radius)
void clear()
void closePath()
qsizetype commandsCapacity() const
qsizetype commandsDataCapacity() const
qsizetype commandsDataSize() const
qsizetype commandsSize() const
QPointF currentPosition() const
void ellipse(float x, float y, float radiusX, float radiusY)
void ellipse(const QRectF &rect)
bool isEmpty() const
void lineTo(QPointF point)
void lineTo(float x, float y)
void moveTo(QPointF point)
void moveTo(float x, float y)
QPointF positionAt(qsizetype index) const
void quadraticCurveTo(float cpX, float cpY, float x, float y)
void quadraticCurveTo(QPointF controlPoint, QPointF endPoint)
void rect(float x, float y, float width, float height)
void rect(const QRectF &rect)
void reserve(qsizetype commandsSize, qsizetype commandsDataSize)
void reserve(qsizetype commandsSize)
void roundRect(float x, float y, float width, float height, float radius)
void roundRect(float x, float y, float width, float height, float radiusTopLeft, float radiusTopRight, float radiusBottomRight, float radiusBottomLeft)
void roundRect(const QRectF &rect, float radius)
void roundRect(const QRectF &rect, float radiusTopLeft, float radiusTopRight, float radiusBottomRight, float radiusBottomLeft)
void setPathWinding(QCanvasPainter::PathWinding winding)
QCanvasPath sliced(qsizetype start, qsizetype count, const QTransform &transform = QTransform()) const
void squeeze()
void swap(QCanvasPath &other)
operator QVariant() const
QCanvasPath &operator=(QCanvasPath &&other)
QCanvasPath &operator=(const QCanvasPath &path)
bool operator!=(const QCanvasPath &lhs, const QCanvasPath &rhs)
bool operator==(const QCanvasPath &lhs, const QCanvasPath &rhs)

상세 설명

페인터 경로는 직사각형, 타원, 선, 곡선 등 여러 그래픽 빌딩 블록으로 구성된 객체입니다. QCanvasPath API는 QCanvasPainter 경로 페인팅과 일치하므로 직접 페인팅하거나 경로에 페인팅하는 코드를 쉽게 조정할 수 있습니다. QCanvasPath를 사용하는 주된 이유는 (정적) 경로를 다시 만들지 않고 경로를 GPU 버퍼에 캐시할 수 있기 때문입니다.

QPainterPath 와 비교하면 QCanvasPath는 경로를 비교하거나 조정하는 기능이 적고 렌더링에 더 최적화되어 있습니다. 특히

  • 두 경로 간의 교집합 또는 빼기 메서드가 없습니다.
  • 경로를 번역하는 메서드가 없습니다.
  • 텍스트를 추가하는 메서드가 없습니다.
  • 채우기 규칙은 항상 WindingFill (0이 아님)이며 OddEvenFill 은 지원되지 않습니다.

기능적인 관점에서 볼 때 QCanvasPath는 HTML 캔버스 Path2D와 더 유사하며, 몇 가지 추가 사항과 API가 QCanvasPainter 와 일치합니다.

경로 그룹 및 캐싱

QCanvasPath를 통해 경로를 페인팅하면 엔진이 경로 지오메트리(정점)를 캐시할 수 있습니다. 이렇게 하면 정적 경로의 성능이 향상되지만 잠재적으로 GPU 메모리 소비가 증가합니다.

fill() 또는 stroke()를 사용하여 QCanvasPath 을 매개변수로 사용하는 경로를 페인팅할 때 pathGroup 을 두 번째 매개변수로 설정할 수 있습니다. 이는 경로가 캐시되는 GPU 버퍼를 정의합니다. 기본적으로 pathGroup0 으로 첫 번째 버퍼가 사용됩니다. pathGroup-1 으로 설정하면 경로에 자체 버퍼가 할당되지 않으며, 시작 경로() 뒤에 명령 및 채우기/획을 사용하여 직접 그리는 경우와 동일한 동적 버퍼가 사용됨을 의미합니다.

경로를 경로 그룹으로 배열하면 렌더링 성능과 GPU 메모리 사용량을 효율적으로 최적화할 수 있습니다. 함께 속해 있고 동시에 자주 변경되는 경로는 최적의 버퍼 사용을 위해 같은 그룹에 속해야 합니다.

경로가 변경되면 해당 지오메트리(버텍스 버퍼)가 자동으로 업데이트됩니다. 경로 그룹의 지오메트리를 업데이트하는 원인은 다음과 같습니다:

상태 변환(QCanvasPainter::transform(), QCanvasPainter::rotate() 등)을 변경해도 경로가 무효화되지 않으므로 캐시된 경로를 이동/확대/회전하는 것이 매우 효율적이라는 점에 유의하세요.

경로를 더 이상 그릴 필요가 없거나 애플리케이션에서 GPU 메모리를 해제해야 하는 경우 QCanvasPainter::removePathGroup()를 호출하여 캐시를 해제할 수 있습니다. 캐시된 경로는 페인터 소멸자 중에 자동으로 해제되므로 일반적으로는 필요하지 않습니다.

QCanvasPainter::addPath() 및 QCanvasPainter::removePathGroup()도 참조하세요 .

멤버 함수 문서

QCanvasPath::QCanvasPath()

빈 경로를 생성합니다.

[explicit] QCanvasPath::QCanvasPath(qsizetype commandsSize, qsizetype commandsDataSize = -1)

빈 경로를 생성하여 commandsSize 양의 명령어와 선택적으로 commandsDataSize 양의 데이터를 위한 공간을 할당합니다. commandsDataSize 매개변수를 지정하지 않으면 경로 명령이 직선(moveTo(), lineTo(), rect())일 때 최적의 양인 2 * commandsSize 데이터 양을 위한 공간이 자동으로 예약됩니다.

올바른 공간을 예약하는 것은 경로 생성 및 메모리 사용량 최적화를 위한 것입니다. 경로에 명령을 추가하는 동안 충분한 공간이 자동으로 확보되므로 필수는 아닙니다.

reserve()도 참조하세요 .

QCanvasPath::QCanvasPath(const QCanvasPath &path)

주어진 path 의 복사본인 경로를 생성합니다.

QCanvasPath::QCanvasPath(QCanvasPath &&other)

이동 - other 에서 새 QCanvasPath를 생성합니다.

[noexcept] QCanvasPath::~QCanvasPath()

경로를 파괴합니다.

void QCanvasPath::addPath(const QCanvasPath &path, const QTransform &transform = QTransform())

path 을 이 경로에 추가하고, 선택적으로 transform 을 사용하여 경로 지점을 변경합니다. transform 이 제공되지 않거나 ID 행렬인 경우 이 작업은 경로 데이터를 재사용하므로 매우 빠릅니다.

void QCanvasPath::addPath(const QCanvasPath &path, qsizetype start, qsizetype count, const QTransform &transform = QTransform())

start 명령에서 시작하여 count 명령의 양을 포함하여 현재 경로에 path 을 추가합니다. 선택적으로 transform 을 사용하여 경로 지점을 변경할 수 있습니다. startcount 범위가 확인되어 QCanvasPath::commandsSize() 이상으로 명령이 액세스되지 않도록 합니다. 경로가 현재 경로 위치에서 계속되지 않아야 하는 경우 path.positionAt(start - 1) 을 사용하여 moveTo()을 먼저 호출합니다.

void QCanvasPath::arc(float centerX, float centerY, float radius, float a0, float a1, QCanvasPainter::PathWinding direction = QCanvasPainter::PathWinding::ClockWise, QCanvasPainter::PathConnection connection = QCanvasPainter::PathConnection::Connected)

주어진 radius 을 사용하여 QPointF(centerX, centerY)을 중심으로 호를 만들고, a0 라디안 각도에서 시작하여 a1 라디안에서 끝납니다. 호는 주어진 direction 에 걸쳐 있습니다. connectionNotConnected 인 경우 이전 경로가 닫히고 새 하위 경로가 시작됩니다.

void QCanvasPath::arc(QPointF centerPoint, float radius, float a0, float a1, QCanvasPainter::PathWinding direction = QCanvasPainter::PathWinding::ClockWise, QCanvasPainter::PathConnection connection = QCanvasPainter::PathConnection::Connected)

centerPoint 주어진 radius 을 중심으로 a0 라디안 각도에서 시작하여 a1 라디안에서 끝나는 호를 만듭니다. 호는 주어진 direction 에 걸쳐 있습니다. connectionNotConnected 인 경우 이전 경로가 닫히고 새 하위 경로가 시작됩니다.

이 함수는 오버로드된 함수입니다.

void QCanvasPath::arcTo(float x1, float y1, float x2, float y2, float radius)

주어진 radius 과 함께 QPointF(x1, y1) 및 QPointF(x2, y2) 점을 사용하여 호를 생성합니다 .

void QCanvasPath::arcTo(QPointF point1, QPointF point2, float radius)

주어진 radius 과 함께 point1point2 점을 사용하여 호를 생성합니다.

이것은 오버로드된 함수입니다.

void QCanvasPath::beginHoleSubPath()

구멍 하위 경로를 시작합니다. 이는 setPathWinding(QCanvasPainter::PathWinding::ClockWise))에 해당합니다.

beginSolidSubPath()도 참조하세요 .

void QCanvasPath::beginSolidSubPath()

솔리드 하위 경로를 시작합니다. 이는 setPathWinding(QCanvasPainter::PathWinding::CounterClockWise))에 해당합니다.

beginHoleSubPath()도 참조하세요 .

void QCanvasPath::bezierCurveTo(float cp1X, float cp1Y, float cp2X, float cp2Y, float x, float y)

cp1X, cp1Y, cp2X, cp2Y 에 지정된 제어점을 사용하여 현재 위치와 xy 에 지정된 끝점 사이에 큐빅 베지어 커브를 추가합니다.

커브가 추가되면 현재 위치가 커브의 끝점이 되도록 업데이트됩니다.

void QCanvasPath::bezierCurveTo(QPointF controlPoint1, QPointF controlPoint2, QPointF endPoint)

controlPoint1controlPoint2 에서 지정한 제어점을 사용하여 현재 위치와 지정된 endPoint 사이에 큐빅 베지어 커브를 추가합니다.

커브가 추가되면 현재 위치가 커브의 끝점이 되도록 업데이트됩니다.

이 함수는 오버로드된 함수입니다.

void QCanvasPath::circle(float x, float y, float radius)

QPointF(x, y)에 가운데가 있는 원과 지정된 radius 을 경로에 추가합니다.

void QCanvasPath::circle(QPointF centerPoint, float radius)

centerPoint 및 지정된 radius 에 중심이 있는 원을 경로에 추가합니다.

이 함수는 오버로드된 함수입니다.

void QCanvasPath::clear()

경로 명령과 데이터를 지웁니다.

경로 명령이 변경되어 경로를 다시 만들 때 이 함수를 호출합니다. 메모리 사용량에는 영향을 주지 않으므로 reserve() 및 squeeze()을 사용합니다.

reserve() 및 squeeze()도 참조하세요 .

void QCanvasPath::closePath()

하위 경로의 시작 부분에 선을 그려서 현재 하위 경로를 닫고 자동으로 새 경로를 시작합니다.

qsizetype QCanvasPath::commandsCapacity() const

경로에 있는 명령의 용량을 반환합니다.

commandsDataCapacity() 및 reserve()도 참조하세요 .

qsizetype QCanvasPath::commandsDataCapacity() const

경로에 있는 명령 데이터의 용량을 반환합니다.

commandsCapacity() 및 reserve()도 참조하세요 .

qsizetype QCanvasPath::commandsDataSize() const

경로에 있는 명령어 데이터의 양을 반환합니다.

명령 데이터는 기본적으로 명령에 필요한 포인트를 의미합니다.

참고: 일부 경로 요소에는 여러 개의 데이터 포인트가 필요합니다. 예를 들어 closePath 에는 0, moveTolineTo 에는 2, bezierCurveTo 에는 6, roundRect 에는 34 데이터 포인트가 필요합니다.

qsizetype QCanvasPath::commandsSize() const

경로에 있는 명령의 개수를 반환합니다.

참고: 일부 경로 요소에는 여러 개의 명령어가 필요합니다. 예를 들어 moveTolineTo 에는 1 명령이 필요하고, bezierCurveTo 에는 6 명령, roundRect 10 명령이 필요합니다.

QPointF QCanvasPath::currentPosition() const

경로의 현재 위치를 반환합니다. 이는 이전 경로 명령(moveTo, lineTo, bezierCurveTo 등)이 종료된 위치를 의미합니다. 경로가 비어 있으면 (0.0, 0.0)을 반환합니다.

void QCanvasPath::ellipse(float x, float y, float radiusX, float radiusY)

(x, y)을 중심으로 반지름이 radiusX, radiusY 으로 정의된 타원을 만들어 경로에 닫힌 하위 경로로 추가합니다.

void QCanvasPath::ellipse(const QRectF &rect)

직사각형 rect 내에 타원을 만들어 경로에 닫힌 하위 경로로 추가합니다.

이 함수는 오버로드된 함수입니다.

bool QCanvasPath::isEmpty() const

경로가 비어 있으면 true를 반환합니다.

clear참조하세요 .

void QCanvasPath::lineTo(QPointF point)

현재 위치에서 지정된 point 까지 직선을 추가합니다. 직선이 그려진 후 현재 위치가 직선의 끝점이 되도록 업데이트됩니다.

이 함수는 오버로드된 함수입니다.

void QCanvasPath::lineTo(float x, float y)

현재 위치에서 지점까지 선을 그립니다(x, y).

이 함수는 오버로드된 함수입니다.

void QCanvasPath::moveTo(QPointF point)

현재 지점을 지정된 point 으로 이동하여 암시적으로 새 하위 경로를 시작하고 이전 경로를 닫습니다.

이 함수는 오버로드된 함수입니다.

void QCanvasPath::moveTo(float x, float y)

현재 위치를 (x, y)로 이동하고 새 하위 경로를 시작하여 이전 경로를 암시적으로 닫습니다.

이 함수는 오버로드된 함수입니다.

QPointF QCanvasPath::positionAt(qsizetype index) const

index 에서 경로의 위치를 반환합니다. 즉, 경로 명령(moveTo, lineTo, bezierCurveTo 등)이 index 에 있는 위치를 의미합니다. 인덱스는 0commandsSize() - 1 사이여야 합니다. 경로가 비어 있으면 (0.0, 0.0)을 반환합니다.

void QCanvasPath::quadraticCurveTo(float cpX, float cpY, float x, float y)

(cpX, cpY)로 지정된 제어점을 사용하여 현재 점과 끝점 (x, y) 사이에 이차 베지어 곡선을 추가합니다.

void QCanvasPath::quadraticCurveTo(QPointF controlPoint, QPointF endPoint)

controlPoint 으로 지정된 제어점을 사용하여 현재 위치와 지정된 endPoint 사이에 이차 베지어 곡선을 추가합니다.

이 함수는 오버로드된 함수입니다.

void QCanvasPath::rect(float x, float y, float width, float height)

주어진 widthheight 를 사용하여 QPointF(x, y)에 위치한 직사각형을 만듭니다.

void QCanvasPath::rect(const QRectF &rect)

로 지정된 사각형을 만듭니다. rect

이 함수는 오버로드된 함수입니다.

void QCanvasPath::reserve(qsizetype commandsSize, qsizetype commandsDataSize)

QCanvasPath 의 내부 메모리에 지정된 양의 공간을 예약합니다.

최소 commandsSize 명령과 commandsDataSize 데이터 포인트에 대한 메모리 할당을 시도합니다. 일부 경로 요소에는 여러 명령어가 필요합니다( commandsSize() 및 commandsDataSize() 참조).

올바른 공간을 확보하는 것이 경로 생성 및 메모리 사용 최적화에 도움이 됩니다. 경로에 명령을 추가하는 동안 충분한 공간이 자동으로 확보되므로 필수는 아닙니다.

squeeze(), commandsCapacity() 및 commandsDataCapacity()도 참조하세요 .

void QCanvasPath::reserve(qsizetype commandsSize)

QCanvasPath 의 내부 메모리에 지정된 양의 공간을 예약합니다.

최소 commandsSize 명령에 대한 메모리 할당을 시도합니다. 일부 경로 요소에는 여러 명령어가 필요합니다( commandsSize() 및 commandsDataSize() 참조).

경로 명령이 직선(moveTo(), lineTo(), rect())일 때 최적의 양인 2 * commandsSize 양의 데이터를 위한 공간이 자동으로 예약됩니다.

올바른 공간을 예약하는 것은 경로 생성 및 메모리 사용량 최적화를 위한 것입니다. 경로에 명령을 추가하는 동안 충분한 공간이 자동으로 확보되므로 필수는 아닙니다.

이 함수는 과부하가 걸린 함수입니다.

squeeze(), commandsCapacity() 및 commandsDataCapacity()도 참조하세요 .

void QCanvasPath::roundRect(float x, float y, float width, float height, float radius)

모서리가 둥근 직사각형 x, y, width, height 을 경로에 추가합니다. 모서리는 주어진 radius 의 1/4 원입니다.

void QCanvasPath::roundRect(float x, float y, float width, float height, float radiusTopLeft, float radiusTopRight, float radiusBottomRight, float radiusBottomLeft)

모서리가 둥근 직사각형 x, y, width, height 을 경로에 추가합니다. 모서리는 각각 반지름이 radiusTopLeft, radiusTopRight radiusBottomRightradiusBottomLeft 인 1/4 원입니다.

void QCanvasPath::roundRect(const QRectF &rect, float radius)

모서리가 둥근 주어진 사각형 rect 을 경로에 추가합니다. 모서리는 주어진 radius 의 1/4 원입니다.

이 함수는 오버로드된 함수입니다.

void QCanvasPath::roundRect(const QRectF &rect, float radiusTopLeft, float radiusTopRight, float radiusBottomRight, float radiusBottomLeft)

모서리가 둥근 직사각형 rect 을 경로에 추가합니다. 모서리는 각각 반지름이 radiusTopLeft, radiusTopRight radiusBottomRightradiusBottomLeft 인 1/4 원입니다.

이것은 오버로드된 함수입니다.

void QCanvasPath::setPathWinding(QCanvasPainter::PathWinding winding)

현재 하위 경로 windingQCanvasPainter::CounterClockWise (기본값) 또는 QCanvasPainter::ClockWise 로 설정합니다. CounterClockWise는 단선 하위 경로를 그리는 반면 ClockWise는 구멍을 그립니다.

참고: 이 명령은 lineTo, moveTo 등과 유사한 명령이므로 변경된 권선이 적용될 나머지 명령보다 먼저 권선을 설정해야 합니다.

QCanvasPath QCanvasPath::sliced(qsizetype start, qsizetype count, const QTransform &transform = QTransform()) const

start 명령에서 시작하여 count 명령량을 포함하여 이 경로의 명령이 포함된 새 경로를 반환하며, 선택적으로 transform 를 사용하여 경로 지점을 변경할 수 있습니다.

startcount 범위가 확인되므로 commandsSize() 이상으로 명령이 액세스되지 않습니다. start 의 명령이 MoveTo 이 아닌 경우 첫 번째 명령은 MoveTo 로 대체되어 이 슬라이스가 개별 경로가 됩니다.

void QCanvasPath::squeeze()

경로 명령과 데이터를 저장하는 데 필요하지 않은 메모리를 해제합니다. reserve () 호출 후 메모리 사용량을 줄이는 데 사용할 수 있습니다.

일반적으로는 사용할 필요가 없지만 많은 요소(lineTo, bezierCurveTo 등)를 예약하거나 추가하여 경로 크기가 커졌다가 향후 크기가 훨씬 작아질 것으로 예상되는 경우 reserve() 를 먼저 호출한 다음 squeeze() 을 호출하면 일부 메모리를 해제하는 데 유용할 수 있습니다.

reserve()도 참조하세요 .

[noexcept] void QCanvasPath::swap(QCanvasPath &other)

이 경로를 other 로 바꿉니다. 이 작업은 매우 빠르며 실패하지 않습니다.

QCanvasPath::operator QVariant() const

경로를 QVariant 로 반환합니다.

[noexcept] QCanvasPath &QCanvasPath::operator=(QCanvasPath &&other)

이동-이 other 인스턴스를 QCanvasPath 인스턴스에 할당합니다.

QCanvasPath &QCanvasPath::operator=(const QCanvasPath &path)

주어진 path 을 이 경로에 할당하고 이 경로에 대한 참조를 반환합니다.

관련 비회원

[noexcept] bool operator!=(const QCanvasPath &lhs, const QCanvasPath &rhs)

lhs 경로가 rhs 과 다르면 true 을 반환하고, 그렇지 않으면 false 을 반환합니다.

operator==()도 참조하세요 .

[noexcept] bool operator==(const QCanvasPath &lhs, const QCanvasPath &rhs)

lhs 경로가 rhs, false 경로와 같으면 true 을 반환합니다.

operator!=()도 참조하세요 .

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.