在 QTextEdit 中放置图像的几种方法
我认为这是一个非常简单的问题,但是当我复制图像时我无法将其粘贴到 QTextEdit 中?粘贴无效!另外我想知道如何拖放图片。
顺便说一句,我使用以下代码将图片插入 QTextEdit:
QTextEdit *textEditor = new QTextEdit(0);
QTextDocumentFragment fragment;
fragment = QTextDocumentFragment::fromHtml("<img src='C:\\aaa.jpg'>");
textEditor->textCursor().insertFragment(fragment);
textEditor->setVisible(true);
是否推荐?你如何进行这个操作?
I think this is a very simple question, but when I copy an image I can't paste it in a QTextEdit? Paste is inactive! Also I would like to know how to drag-and-drop a picture.
BTW I use the following code in order to insert a picture into a QTextEdit:
QTextEdit *textEditor = new QTextEdit(0);
QTextDocumentFragment fragment;
fragment = QTextDocumentFragment::fromHtml("<img src='C:\\aaa.jpg'>");
textEditor->textCursor().insertFragment(fragment);
textEditor->setVisible(true);
Is it recommended? How do you do this operation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
第二种方式是这样的:
第三种方式是继承QTextEdit并重新实现
canInsertFromMimeData
和insertFromMimeData
函数,如下所示。顺便说一句,此方法允许使用拖放或复制粘贴机制。只是想分享我在长期调查中发现的内容:)。
The second way is this:
The third way is to inherit QTextEdit and reimplement
canInsertFromMimeData
andinsertFromMimeData
functions as follows. By the way this method allows to use drag-and-drop or copy-paste mechanisms.Just wanted to share what I have found during long investigation :).
对于纳雷克的第二种方式,如果你使用
当您打开 .html 文件时,图像将无法正确显示。
所以只需将其修改为:
For Narek's the second way, if you use
when you open the .html file the image will not be shown correctly.
So just modify it to: