简体   繁体   English

如何在QQuickPaintedItem中选择区域

[英]How select an area in QQuickPaintedItem

I want to build a selection tool for my qml image editor. 我想为我的qml图像编辑器构建一个选择工具。

For this, I'm looking for an similar function like setSelectedArea in a QGraphicsScene . 为此,我正在QGraphicsScene寻找类似setSelectedArea函数。 Has someone a solution for this? 有人对此有解决方案吗?

Greetings 问候

Edit: Maybe I can write a Plugin for my selection tool which extends the QQuickItem and draw a QPolygon with openGL. 编辑:也许我可以为我的选择工具编写一个插件,以扩展QQuickItem并使用openGL绘制QPolygon。

You need to implement selection yourself. 您需要自己实施选择。

You can create MouseArea that will track mouse activity and update selected rect accordingly. 您可以创建MouseArea来跟踪鼠标活动并相应地更新选定的矩形。 I mean something like this: 我的意思是这样的:

DocumentViewer { // Your QQuickPaintedItem
    id: viewer
    MouseArea {
        anchors.fill: parent
        acceptedButtons: Qt.LeftButton
        property real originX: 0
        property real originY: 0
        onPressed: {
            originX = mouse.x
            originY = mouse.y
        }
        onPositionChanged: {
            var width = mouse.x - originX
            var height = mouse.y - originY
            viewer.selectionRect = Qt.rect(originX, originY, width, height)
        }
    }
}

Then you'll be able to update and paint the selection rectangle in your viewer's selectionRect property setter. 然后,您将能够在查看器的selectionRect属性设置器中更新和绘制选择矩形。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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