Pyqt 简明教程

PyQt - QClipboard

QClipboard 类提供对系统范围剪贴板的访问,提供在应用程序之间拷贝/粘贴数据的简洁机制。它的操作类似于 QDrag 类,使用类似的数据类型。

The QClipboard class provides access to system-wide clipboard that offers a simple mechanism to copy and paste data between applications. Its action is similar to QDrag class and uses similar data types.

QApplication 类有一个静态方法 clipboard(),它返回对剪贴板对象的引用。可以将任何类型的 MimeData 复制到剪贴板或从剪贴板粘贴。

QApplication class has a static method clipboard() which returns reference to clipboard object. Any type of MimeData can be copied to or pasted from the clipboard.

以下是一些常用的剪贴板类的方法: -

Following are the clipboard class methods that are commonly used −

Sr.No.

Methods & Description

1

clear() Clears clipboard contents

2

setImage() Copies QImage into clipboard

3

setMimeData() Sets MIME data into clipboard

4

setPixmap() Copies Pixmap object in clipboard

5

setText() Copies QString in clipboard

6

text() Retrieves text from clipboard

与剪贴板对象关联的信号是 -

Signal associated with clipboard object is −

Sr.No.

Method & Description

1

dataChanged() Whenever clipboard data changes

Example

在以下示例中,两个 TextEdit 对象和两个 Pushbutton 被添加到一个顶级窗口。

In the following example, two TextEdit objects and two Pushbuttons are added to a top level window.

首先,实例化剪贴板对象。textedit 对象的 Copy() 方法将数据复制到系统剪贴板。当按下粘贴按钮时,它会获取剪贴板数据并将其粘贴到另一个 textedit 对象。

To begin with the clipboard object is instantiated. Copy() method of textedit object copies the data onto the system clipboard. When the Paste button is clicked, it fetches the clipboard data and pastes it in other textedit object.

qclipboard output1
qclipboard output2
qclipboard output3