qt剪贴板
全局剪贴板
剪贴板数据更新时发送信号
1 | [signal] void QClipboard::dataChanged(); |
获取剪贴板数据
1 | const QMimeData *mimeData(QClipboard::Mode mode = Clipboard) const; |
设置剪贴板数据
1 | void setMimeData(QMimeData *src, QClipboard::Mode mode = Clipboard); |
QMimeData
QMimeData 存储剪贴板数据
通常由对象 QDrag
和 QClipboard
使用
Tester | Getter | Setter | MIME Types |
---|---|---|---|
hasText() | text() | setText() | text/plain |
hasHtml() | html() | setHtml() | text/html |
hasUrls() | urls() | setUrls() | text/uri-list |
hasImage() | imageData() | setImageData() | image/ * |
hasColor() | colorData() | setColorData() | application/x-color |
example
1 | void MyWidget::dragEnterEvent(QDragEnterEvent *event) |
存储自定义数据
Custom data can be stored directly in a QMimeData object as a QByteArray using setData(). For example:
1
2
3QByteArray csvData = ...;
QMimeData *mimeData = new QMimeData;
mimeData->setData("text/csv", csvData);We can subclass QMimeData and reimplement hasFormat(), formats(), and retrieveData().
If the drag and drop operation occurs within a single application, we can subclass QMimeData and add extra data in it, and use a qobject_cast() in the receiver’s drop event handler.
For example:
1
2
3
4
5
6
7
8void MyWidget::dropEvent(QDropEvent *event)
{
const MyMimeData *myData =
qobject_cast<const MyMimeData *>(event->mimeData());
if (myData) {
// access myData's data directly (not through QMimeData's API)
}
}
QTextEdit
文本输入框的粘贴
重写该函数,返回值决定是否允许粘贴
1
[virtual protected] bool QTextEdit::canInsertFromMimeData(const QMimeData *source) const
重写该函数,自定义粘贴
1
[virtual protected] void QTextEdit::insertFromMimeData(const QMimeData *source)
# 相关文章
1.qt档案库
2.配置Qt&Android开发环境
3.qt增加mqtt模块
4.定制qtcreator
5.qt富文本生成&解析
6.Qt MVC模型
7.QThread使用方法
8.QList去重
1.qt档案库
2.配置Qt&Android开发环境
3.qt增加mqtt模块
4.定制qtcreator
5.qt富文本生成&解析
6.Qt MVC模型
7.QThread使用方法
8.QList去重