이 페이지에서

Qt Quick 예제 - MouseArea

이것은 QML에서 ` MouseArea ` 유형의 예제입니다.

아래에 이벤트 상태 텍스트가 표시된 빨간색 사각형을 클릭하고 파란색 사각형을 마우스로 드래그하세요.

MouseArea 예제는 MouseArea 를 사용하여 클릭 및 드래그에 반응하는 방법을 보여줍니다. 자세한 내용은 ‘ Qt Quick 의 중요한 개념 - 사용자 입력’을 참조하십시오.

예제 실행

다음 위치에서 예제를 실행할 수 있습니다.

MouseArea 동작

빨간색 사각형 내부를 클릭하면, Text 타입이 QML에서 사용할 수 있는 해당 클릭의 여러 속성을 나열합니다. 마우스 버튼이 눌린 상태에서 MouseArea 내부에 머무르는 동안 빨간색 사각형의 불투명도가 감소합니다.

MouseArea 내에서는 클릭이나 기타 개별적인 작업이 발생할 때 신호가 발송됩니다.

onPressAndHold: btn.text = qsTr('Press and hold')
onClicked: (mouse) => { btn.text = qsTr('Clicked (wasHeld=') + mouse.wasHeld + ')' }
onDoubleClicked: btn.text = qsTr('Double clicked')

MouseArea 또한 이 기능을 사용하여 항목을 드래그할 수도 있습니다. drag 속성의 매개변수를 설정하면, 사용자가 마우스 영역 경계 내에서 드래그를 시작할 때 대상 항목이 드래그됩니다.

drag.target: blueSquare
drag.axis: Drag.XAndYAxis
drag.minimumX: 0
drag.maximumX: box.width - parent.width
drag.minimumY: 0
drag.maximumY: box.height - parent.width

예제 프로젝트 @ code.qt.io

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