QWheelEvent Class

QWheelEvent 클래스에는 휠 이벤트를 설명하는 매개변수가 포함되어 있습니다. 더 보기...

Header: #include <QWheelEvent>
CMake: find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: QT += gui
상속합니다: QSinglePointEvent

공용 함수

QWheelEvent(const QPointF &pos, const QPointF &globalPos, QPoint pixelDelta, QPoint angleDelta, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase, bool inverted, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized, const QPointingDevice *device = QPointingDevice::primaryPointingDevice())
QPoint angleDelta() const
bool inverted() const
Qt::ScrollPhase phase() const
QPoint pixelDelta() const

재구현된 공용 함수

virtual bool isBeginEvent() const override
virtual bool isEndEvent() const override
virtual bool isUpdateEvent() const override

상세 설명

휠 이벤트는 마우스 커서 아래의 위젯으로 전송되지만, 해당 위젯이 이벤트를 처리하지 않으면 포커스 위젯으로 전송됩니다. 휠 이벤트는 마우스 휠과 트랙패드 스크롤 제스처 모두에 대해 생성됩니다. 휠 이벤트 델타를 읽는 방법에는 두 가지가 있습니다. angleDelta()는 휠 각도 단위의 델타를 반환합니다. 이 값은 항상 제공됩니다. pixelDelta()는 화면 픽셀 단위의 델타를 반환하며, macOS와 같이 고해상도 트랙패드가 있는 플랫폼에서 사용할 수 있습니다. 이 경우 device()->type()은 QInputDevice::DeviceType::Touchpad를 반환합니다.

position() 및 globalPosition() 함수는 이벤트 발생 시 마우스 커서의 위치를 반환합니다.

휠 이벤트에는 수신자가 이벤트를 원하는지 여부를 나타내는 특수 수락 플래그가 포함되어 있습니다. 휠 이벤트를 처리하지 않는 경우 ignore()를 호출해야 상위 위젯으로 이벤트가 전송됩니다.

QWidget::setEnabled() 함수는 위젯의 마우스 및 키보드 이벤트를 활성화 또는 비활성화하는 데 사용할 수 있습니다.

이벤트 핸들러 QWidget::wheelEvent()는 휠 이벤트를 수신합니다.

QMouseEventQWidget::grabMouse()도 참조하세요 .

멤버 함수 문서

QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF &globalPos, QPoint pixelDelta, QPoint angleDelta, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase, bool inverted, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized, const QPointingDevice *device = QPointingDevice::primaryPointingDevice())

휠 이벤트 객체를 생성합니다.

pos 은 창 내에서 마우스 커서의 위치를 제공합니다. 전역 좌표의 위치는 globalPos 로 지정됩니다.

pixelDelta 는 화면에서 픽셀 단위의 스크롤 거리를 포함하고 angleDelta 는 휠 회전 각도를 포함합니다. pixelDelta 은 선택 사항이며 null일 수 있습니다.

이벤트 발생 시 마우스 및 키보드 상태는 buttonsmodifiers 에 의해 지정됩니다.

이벤트의 스크롤 단계는 phase 에 의해 지정되며 source 은 이것이 진짜 이벤트인지 인위적인(합성된) 이벤트인지를 나타냅니다.

시스템이 이벤트와 함께 전달되는 델타 값을 반전하도록 구성된 경우(예: macOS의 터치패드 자연 스크롤) invertedtrue 이어야 합니다. 그렇지 않으면 inverted 입니다. false

휠 이벤트가 발생한 장치는 device 로 지정됩니다.

position(), globalPosition(), angleDelta(), pixelDelta(), phase(), inverted(), device()도 참조하세요 .

QPoint QWheelEvent::angleDelta() const

휠이 회전한 상대적인 양을 8분의 1도 단위로 반환합니다. 양수 값은 휠이 사용자로부터 앞으로 회전했음을 나타내고 음수 값은 휠이 사용자 쪽으로 뒤로 회전했음을 나타냅니다. angleDelta().y() 은 이전 이벤트 이후 일반적인 수직 마우스 휠이 회전한 각도를 제공합니다. angleDelta().x() 은 마우스에 수평 휠이 있는 경우 수평 마우스 휠이 회전한 각도를 제공하고 그렇지 않으면 0으로 유지됩니다. 일부 마우스는 사용자가 휠을 기울여 수평 스크롤을 수행할 수 있으며, 일부 터치패드는 수평 스크롤 제스처를 지원하므로 angleDelta().x() 에도 표시됩니다.

대부분의 마우스 유형은 15도 단위로 작동하며, 이 경우 델타 값은 120의 배수, 즉 120단위 * 1/8 = 15도입니다.

그러나 일부 마우스는 휠의 해상도가 더 미세하여 120단위(15도 미만)보다 작은 델타 값을 전송합니다. 이러한 가능성을 지원하기 위해 120 값에 도달할 때까지 이벤트의 델타 값을 누적적으로 더한 다음 위젯을 스크롤하거나 각 휠 이벤트에 대한 응답으로 위젯을 부분적으로 스크롤할 수 있습니다. 하지만 보다 네이티브한 느낌을 제공하려면 pixelDelta()를 사용할 수 있는 플랫폼에서 사용하는 것이 좋습니다.

예시:

void MyWidget::wheelEvent(QWheelEvent *event)
{
    QPoint numPixels = event->pixelDelta();
    QPoint numDegrees = event->angleDelta() / 8;

    if (!numPixels.isNull()) {
        scrollWithPixels(numPixels);
    } else if (!numDegrees.isNull()) {
        QPoint numSteps = numDegrees / 15;
        scrollWithDegrees(numSteps);
    }

    event->accept();
}

참고: phases 스크롤을 지원하는 플랫폼에서는 델타가 null일 수 있습니다:

  • 스크롤이 곧 시작되지만 거리가 아직 변경되지 않은 경우(Qt::ScrollBegin),
  • 또는 스크롤이 종료되었고 거리가 더 이상 변경되지 않은 경우(Qt::ScrollEnd).

참고: 각도 델타 속성에 대한 게터 함수.

pixelDelta()도 참조하세요 .

bool QWheelEvent::inverted() const

이벤트와 함께 전달된 델타 값이 반전되었는지 여부를 반환합니다.

일반적으로 수직 휠은 휠의 상단이 휠을 조작하는 손에서 멀어지면 델타 값이 양수인 QWheelEvent 를 생성합니다. 마찬가지로 수평으로 휠을 움직일 때 휠의 상단이 왼쪽으로 이동하면 델타 값이 양수인 QWheelEvent 이 생성됩니다.

그러나 일부 플랫폼에서는 위에서 설명한 것과 동일한 작업을 수행하면 음의 델타 값이 생성되도록 구성할 수 있습니다(크기는 동일). 반전 속성을 사용하면 휠 이벤트 소비자는 시스템 설정에 관계없이 특정 위젯에 대해서만 항상 휠의 방향을 따르도록 선택할 수 있습니다. (예를 들어 사용자가 시각적 텀블러가 회전하는 것과 같은 방향으로 휠을 회전하는 경우를 들 수 있습니다. 또 다른 사용 사례는 슬라이더 핸들이 시스템 구성에 관계없이 터치패드에서 손가락의 이동 방향을 따르도록 만드는 것입니다.)

참고: 많은 플랫폼에서는 이러한 정보를 제공하지 않습니다. 이러한 플랫폼에서는 반전하면 항상 거짓을 반환합니다.

참고: 반전된 프로퍼티에 대한 게터 함수.

[override virtual] bool QWheelEvent::isBeginEvent() const

재구현합니다: QSinglePointEvent::isBeginEvent() const.

이 이벤트의 phase()가 Qt::ScrollBegin 인 경우 true 를 반환합니다.

[override virtual] bool QWheelEvent::isEndEvent() const

재구현합니다: QSinglePointEvent::isEndEvent() const.

이 이벤트의 phase()가 Qt::ScrollEnd 인 경우 true 를 반환합니다.

[override virtual] bool QWheelEvent::isUpdateEvent() const

재구현합니다: QSinglePointEvent::isUpdateEvent() const.

이 이벤트의 phase()가 Qt::ScrollUpdate 또는 Qt::ScrollMomentum 인 경우 true 를 반환합니다.

Qt::ScrollPhase QWheelEvent::phase() const

이 휠 이벤트의 스크롤 단계를 반환합니다.

참고: Qt::ScrollBeginQt::ScrollEnd 페이즈는 현재 macOS에서만 지원됩니다.

참고: 프로퍼티 페이즈에 대한 게터 함수.

QPoint QWheelEvent::pixelDelta() const

화면의 스크롤 거리를 픽셀 단위로 반환합니다. 이 값은 macOS와 같이 고해상도 픽셀 기반 델타 값을 지원하는 플랫폼에서 제공됩니다. 이 값은 화면에서 콘텐츠를 스크롤할 때 직접 사용해야 합니다.

예시:

void MyWidget::wheelEvent(QWheelEvent *event)
{
    QPoint numPixels = event->pixelDelta();
    QPoint numDegrees = event->angleDelta() / 8;

    if (!numPixels.isNull()) {
        scrollWithPixels(numPixels);
    } else if (!numDegrees.isNull()) {
        QPoint numSteps = numDegrees / 15;
        scrollWithDegrees(numSteps);
    }

    event->accept();
}

참고: 스크롤을 지원하는 플랫폼에서 phases, 델타는 null일 수 있습니다:

  • 스크롤이 곧 시작되지만 거리가 아직 변경되지 않은 경우(Qt::ScrollBegin),
  • 또는 스크롤이 끝났고 거리가 더 이상 변경되지 않은 경우(Qt::ScrollEnd).

참고: X11에서 이 값은 드라이버에 따라 다르며 신뢰할 수 없으므로 angleDelta()를 대신 사용하세요.

참고: 픽셀델타 속성에 대한 게터 함수.

© 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.