QTextEdit中添加图片
2015-11-19 10:30
465 查看
qt中文本编辑框qtextedit,如果希望向文本编辑框中添加图片
有两种方法
第一个:通过URL自愿形式
QTextEdit *editor=new QTextEdit;
this->editor->append(“<img src=/”1.png/n //通过URL来插入到editor中
第二个:通过QTextImageFormat,利用QTextCursor来插入到文本编辑中
QTextImageFormat imageFormat; //保存图片格式对象
imageFormat.setName(“1.png”);
QTextCursor cursor; //编辑指针标
cursor.insertImage(imageFormat); //通过编辑指针表把图片格式的文件插入到资源中
还可以借助QTextDocument把图片作为资源添加到QTextEdit中
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit.
QTextDocument is a container for structured rich text documents,
A QTextDocument can be edited programmatically using a QTextCursor,
[QTextDocument]类包含了qtextedit可以查看和编辑的格式化的文本,是一个结构化的富文本容器,一个QTextDocument 对象可以通过QTextCursor在程序中编辑。
把图片添加到资源缓存中
QTextDocument *document=new QTextDocument(this); //图片容器
QUrl url;
url = QUrl::fromLocalFile(“1.png”); //指定Url
document->addResource(QTextDocument::ImageResource,url,QVariant(url)); //添加资源到document容器中
QT中给的Demo感觉好麻烦
有两种方法
第一个:通过URL自愿形式
QTextEdit *editor=new QTextEdit;
this->editor->append(“<img src=/”1.png/n //通过URL来插入到editor中
第二个:通过QTextImageFormat,利用QTextCursor来插入到文本编辑中
QTextImageFormat imageFormat; //保存图片格式对象
imageFormat.setName(“1.png”);
QTextCursor cursor; //编辑指针标
cursor.insertImage(imageFormat); //通过编辑指针表把图片格式的文件插入到资源中
还可以借助QTextDocument把图片作为资源添加到QTextEdit中
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit.
QTextDocument is a container for structured rich text documents,
A QTextDocument can be edited programmatically using a QTextCursor,
[QTextDocument]类包含了qtextedit可以查看和编辑的格式化的文本,是一个结构化的富文本容器,一个QTextDocument 对象可以通过QTextCursor在程序中编辑。
把图片添加到资源缓存中
QTextDocument *document=new QTextDocument(this); //图片容器
QUrl url;
url = QUrl::fromLocalFile(“1.png”); //指定Url
document->addResource(QTextDocument::ImageResource,url,QVariant(url)); //添加资源到document容器中
QT中给的Demo感觉好麻烦
相关文章推荐
- Ⅰ.2.6.7 如何测试QListView (Qt 3)
- Qt之窗体透明
- 使用Qt正则表达式提取全路径的文件名
- QT: :QWheelEvent
- QT 应用程序关闭某个窗口时,关闭打开的所有其他窗口并退出程序
- Qt应用程序的发布 exe文件图标设置
- Qt入门-提示、警告、错误、询问、关于对话框
- Qt之操作数据库(SQLite)
- QT 使用全局变量的方法
- qtcreator 程序出现Failed to load platform plugin “windows”的错误
- it could not find or load the Qt platform plugin "windows"
- 我的QT5学习之路(三)——模板库、工具类和控件(中)
- 命令行执行Qt程序
- 命令行执行Qt程序
- Qt程序启动画面播放(gif与swf两种动画格式) - 路上的脚印
- QTCreator项目转移到VS项目步骤、中文乱码解决方案
- 老李分享:qtp自动化测试框架赏析-关键字自动化测试框架(二)
- QT QTableWidget 用法总结
- ubuntu 下在应用程序列表中创建QTCREATOR快捷图标
- Qt---在QLabel上实现系统时间