使用 cursor->insertImage()插入图片
QTextImageFormat(图片格式)
内联图像由 Unicode 值 U+FFFC(对象替换字符)表示,该值具有关联的 QTextImageFormat。图像格式使用setName() 指定用于查找图像的名称。图像将占据的矩形的大小使用setWidth() 和setHeight() 以像素为单位指定。所需的图像质量可以使用setQuality() 进行设置。
常用的函数为:
setHeight() | 设置图片高度 |
setName() | 设置路径 |
setWidth() | 设置宽度 |
setQuality() | 设置质量 |
isvalid() | 是否合规 |
setQuality:设置导出器在导出图像时应使用的质量。如果质量设置为介于 0 和 100 之间的值,则 QTextDocumentWriter将在导出到 ODF 文件时导出具有此处设置的质量的 jpg 图像。或者,如果质量设置为 100(默认)或更高,它将导出 png 图像。
resize(800,800);
QTextEdit *text=new QTextEdit(this);
text->setFixedSize(500,500);
text->move(100,100);
QTextCursor cursor=text->textCursor();//获取光标位置
QTextImageFormat imagefromat;
imagefromat.setName(":/new/prefix1/E:/image/img.jpg");//设置路径
imagefromat.setWidth(400);
imagefromat.setHeight(400);
cursor.insertImage(imagefromat);