QRubberBand Class
QRubberBand 클래스는 선택 영역이나 경계를 나타낼 수 있는 직사각형 또는 선을 제공합니다. 더 보기...
Header: | #include <QRubberBand> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Widgets) target_link_libraries(mytarget PRIVATE Qt6::Widgets) |
qmake: | QT += widgets |
상속합니다: | QWidget |
공용 타입
enum | Shape { Line, Rectangle } |
공용 함수
QRubberBand(QRubberBand::Shape s, QWidget *p = nullptr) | |
virtual | ~QRubberBand() |
void | move(int x, int y) |
void | move(const QPoint &p) |
void | resize(int width, int height) |
void | resize(const QSize &size) |
void | setGeometry(const QRect &rect) |
void | setGeometry(int x, int y, int width, int height) |
QRubberBand::Shape | shape() const |
보호된 함수
virtual void | initStyleOption(QStyleOptionRubberBand *option) const |
재구현된 보호 함수
virtual void | changeEvent(QEvent *e) override |
virtual bool | event(QEvent *e) override |
virtual void | moveEvent(QMoveEvent *) override |
virtual void | paintEvent(QPaintEvent *) override |
virtual void | resizeEvent(QResizeEvent *) override |
virtual void | showEvent(QShowEvent *e) override |
상세 설명
고무줄은 종종 새로운 경계 영역을 표시하는 데 사용됩니다(예: 도킹 해제 중인 QSplitter 또는 QDockWidget ). 이전에는 QPainter 및 XOR을 사용하여 구현했지만, 고무줄 아래 창에서 고무줄이 '지워지기' 전에 렌더링이 발생할 수 있으므로 이 접근 방식이 항상 제대로 작동하지 않는 경우가 있습니다.
특정 영역 주위에 고무줄을 렌더링해야 할 때마다(또는 하나의 선을 표현하기 위해) QRubberBand를 만든 다음 setGeometry(), move() 또는 resize()를 호출하여 위치와 크기를 지정할 수 있습니다. 일반적인 패턴은 마우스 이벤트와 함께 이 작업을 수행하는 것입니다. 예를 들어
void Widget::mousePressEvent(QMouseEvent *event) { origin = event->pos(); if (!rubberBand) rubberBand = new QRubberBand(QRubberBand::Rectangle, this); rubberBand->setGeometry(QRect(origin, QSize())); rubberBand->show(); } void Widget::mouseMoveEvent(QMouseEvent *event) { rubberBand->setGeometry(QRect(origin, event->pos()).normalized()); } void Widget::mouseReleaseEvent(QMouseEvent *event) { rubberBand->hide(); // determine selection, for example using QRect::intersects() // and QRect::contains(). }
QRubberBand의 생성자에 부모를 전달하면 고무줄은 부모 내부에만 표시되지만 다른 자식 위젯 위에 유지됩니다. 부모가 전달되지 않으면 QRubberBand가 최상위 위젯으로 작동합니다.
고무줄을 표시하려면 show()를 호출하고 고무줄이 최상위 레벨이 아닐 때도 호출하세요. 위젯을 숨기거나 파괴하면 고무줄이 사라집니다. 고무줄은 생성 시 주어진 shape()에 따라 Rectangle 또는 Line (세로 또는 가로)가 될 수 있습니다.
회원 유형 문서
enum QRubberBand::Shape
이 열거형은 QRubberBand 의 모양을 지정합니다. 이것은 스타일 시스템에 전달되는 드로잉 힌트이며, 각 QStyle 에서 해석할 수 있습니다.
Constant | 값 | 설명 |
---|---|---|
QRubberBand::Line | 0 | QRubberBand 은 수직선 또는 수평선을 나타낼 수 있습니다. 지오메트리는 여전히 rect()로 지정되며 대부분의 스타일에서 선은 지정된 지오메트리를 채웁니다. |
QRubberBand::Rectangle | 1 | QRubberBand 은 직사각형을 나타낼 수 있습니다. 일부 스타일에서는 이를 채워진(종종 반투명) 직사각형 또는 직사각형 윤곽선으로 해석합니다. |
멤버 함수 문서
[explicit]
QRubberBand::QRubberBand(QRubberBand::Shape s, QWidget *p = nullptr)
부모 p 를 가진 s 모양의 고무줄을 만듭니다.
기본적으로 직사각형 고무줄(s 은 Rectangle
)은 마스크를 사용하므로 직사각형의 작은 테두리만 표시됩니다. 일부 스타일(예: 기본 macOS)에서는 이를 변경하고 QWidget::setWindowOpacity()를 호출하여 반투명하게 채워진 선택 사각형을 만듭니다.
[virtual noexcept]
QRubberBand::~QRubberBand()
파괴자.
[override virtual protected]
void QRubberBand::changeEvent(QEvent *e)
다시 구현합니다: QWidget::changeEvent(QEvent * 이벤트).
[override virtual protected]
bool QRubberBand::event(QEvent *e)
다시 구현합니다: QWidget::event(QEvent * 이벤트).
[virtual protected]
void QRubberBand::initStyleOption(QStyleOptionRubberBand *option) const
QRubberBand 의 값으로 option 을 초기화합니다. 이 메서드는 하위 클래스에 QStyleOptionRubberBand 이 필요하지만 모든 정보를 직접 채우고 싶지 않을 때 유용합니다.
QStyleOption::initFrom()도 참조하세요 .
void QRubberBand::move(int x, int y)
고무줄을 포인트로 이동합니다 (x, y).
resize()도 참조하세요 .
void QRubberBand::move(const QPoint &p)
과부하가 걸린 기능입니다.
고무줄을 p 으로 이동합니다.
resize()도 참조하세요 .
[override virtual protected]
void QRubberBand::moveEvent(QMoveEvent *)
다시 구현합니다: QWidget::moveEvent(QMoveEvent * 이벤트).
[override virtual protected]
void QRubberBand::paintEvent(QPaintEvent *)
다시 구현합니다: QWidget::paintEvent(QPaintEvent * 이벤트).
void QRubberBand::resize(int width, int height)
너비가 width, 높이가 height 이 되도록 고무줄의 크기를 조정합니다.
move()도 참조하세요 .
void QRubberBand::resize(const QSize &size)
과부하가 걸린 기능입니다.
새 크기가 size 이 되도록 고무줄의 크기를 조정합니다.
move()도 참조하세요 .
[override virtual protected]
void QRubberBand::resizeEvent(QResizeEvent *)
다시 구현합니다: QWidget::resizeEvent(QResizeEvent * 이벤트).
void QRubberBand::setGeometry(const QRect &rect)
고무줄의 지오메트리를 부모 위젯의 좌표계에 지정된 rect 로 설정합니다.
QWidget::geometry도 참조하세요 .
void QRubberBand::setGeometry(int x, int y, int width, int height)
이것은 오버로드된 함수입니다.
고무줄의 지오메트리를 왼쪽 상단 모서리가 점(x, y)에 있는 직사각형으로 설정하고 width 및 height 으로 지정된 치수를 갖습니다. 지오메트리는 부모 위젯의 좌표계에서 지정됩니다.
QRubberBand::Shape QRubberBand::shape() const
이 고무줄의 모양을 반환합니다. 모양은 제작 시에만 설정할 수 있습니다.
[override virtual protected]
void QRubberBand::showEvent(QShowEvent *e)
다시 구현합니다: QWidget::showEvent(QShowEvent * 이벤트).
© 2025 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.