So it works with QTextImageFormat
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
dir.
cd(QDir::homePath());
ui
->graphicsView
->setRenderHint
(QPainter::SmoothPixmapTransform);
ui
->graphicsView
->setRenderHint
(QPainter::Antialiasing);
ui->graphicsView->setScene(scene);
textItem->setTextInteractionFlags(Qt::TextEditorInteraction);
textItem->setPlainText("test");
QImage *image
= new QImage(dir.
absoluteFilePath("tex.png"));
document
->addResource
(QTextDocument::ImageResource,
QUrl::fromLocalFile(dir.
absoluteFilePath("tex.png")),
*image
);
imageFormat.setName(dir.absoluteFilePath("tex.png"));
imageFormat.setHeight(30);
textItem->setScale(4);
textItem->textCursor().insertImage(imageFormat);
ui->graphicsView->scene()->addItem(textItem);
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QDir dir;
dir.cd(QDir::homePath());
ui->graphicsView->setRenderHint(QPainter::SmoothPixmapTransform);
ui->graphicsView->setRenderHint(QPainter::Antialiasing);
QGraphicsScene *scene = new QGraphicsScene;
ui->graphicsView->setScene(scene);
QGraphicsTextItem *textItem = new QGraphicsTextItem;
textItem->setTextInteractionFlags(Qt::TextEditorInteraction);
textItem->setPlainText("test");
QImage *image = new QImage(dir.absoluteFilePath("tex.png"));
QTextDocument *document = textItem->document();
document->addResource(QTextDocument::ImageResource,QUrl::fromLocalFile(dir.absoluteFilePath("tex.png")),*image);
QTextImageFormat imageFormat;
imageFormat.setName(dir.absoluteFilePath("tex.png"));
imageFormat.setHeight(30);
textItem->setScale(4);
textItem->textCursor().insertImage(imageFormat);
ui->graphicsView->scene()->addItem(textItem);
}
To copy to clipboard, switch view to plain text mode
The project is attached in the zip-file.
The attached screenshot show you the result.
NOTE: You see two windows in the (one) screenshot.
Left you see setScale(1) and right setScale(4)
But in setScale(1) the rendering is not as good as with image.scaledToHeight(30, Qt::SmoothTransformation);
After setting setScale(4) it is better than with image.scaledToHeight(30, Qt::SmoothTransformation); but without scaling it's not so good.
I think SmoothTransformation is not enabled in this case.
How to enable it?
Bookmarks