简体   繁体   中英

Extend MouseArea beyond component

I have a Rectangle with width 1 (a line), which should be draggable:

Rectangle {
    id: recMark
    border.width: 0
    width: 1
    height: parent.height
    y: 0
    color: "red"
    opacity: 0.3
    visible: true
    MouseArea {
        anchors.fill: parent
        drag.target: recMark
        drag.axis: Drag.XAxis

    }
}

Is it possible to extend the mouse area beyond the rectangle, eg 3 pixels around it? Obviously it would be hard to hit the right pixel with the mouse.

You can add negative margins to the MouseArea :

MouseArea {
    anchors.fill: parent
    anchors.margins: -3
    // ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM