PdfSelection QML Type

PDF 文档中文本选择的表示。更多

Import Statement: import QtQuick.Pdf
Inherits:

Item

属性

方法

详细说明

PdfSelection提供了文本字符串及其在边界框内从一点到另一点的几何形状。

要使用鼠标修改选区,将fromto 与输入处理程序的适当属性绑定,使其分别设置为拖动手势开始和结束的位置;绑定hold 属性,使其在拖动手势期间设置为true ,在手势结束时设置为false

PdfSelection还能直接处理输入法查询,以便在iOS等平台上使用文本选择句柄。为此,它必须有键盘焦点。

属性文档

document : PdfDocument

该属性用于保存要选择文本的 PDF 文档。


from : point

从页面左上角开始的起始位置,以像素为单位,用于查找选中的文本。DragHandler 例如,可将其绑定到centroid.pressPosition ,以便从用户按下鼠标按钮并开始拖动的位置开始选择文本。


geometry : list<list<point>>

表单中的一组路径可绑定到PathMultiline 实例的paths 属性,以便在选中的文本区域周围渲染一批矩形:

PdfDocument {
    id: doc
}
PdfSelection {
    id: selection
    document: doc
    from: textSelectionDrag.centroid.pressPosition
    to: textSelectionDrag.centroid.position
    hold: !textSelectionDrag.active
}
Shape {
    ShapePath {
        PathMultiline {
            paths: selection.geometry
        }
    }
}
DragHandler {
    id: textSelectionDrag
    acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus
    target: null
}

另请参阅 PathMultiline


hold : bool

控制是否保持现有选区,无论fromto 有何变化。释放鼠标或触摸点时,可将此属性设置为true ,这样就不会因点绑定发生变化而丢失选区。


page : int

要搜索的页码。

另请参阅 QtQuick::Image::currentFrame


renderScale : real

页面渲染时点与像素的比例。

这用于缩放fromto ,以查找文档中选定字符的范围,因为文档中的位置总是以点为单位。


text : string

fromto 之间的矩形区域找到的文本,如果调用了selectAll() ,则在page 上找到所有文本。


to : point

从页面左上角开始查找所选文本的结束位置(以像素为单位)。例如,可以将其绑定到DragHandlercentroid.position ,以便在用户当前拖动鼠标的位置结束文本选择。


方法文档

void clear()

清除当前选区。


void copyToClipboard()

text 属性中的纯文本复制到系统剪贴板。


void selectAll()

选择当前page 上的所有文本。


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