Re: QImage inserted into QGraphicsTextItem looks fuzzy, when scaling QGraphicsTextIte
In a QTextDocument I can insert images, too. Can I set rules what happens at QGrpahicsTextItem scaling with the QAbstractTextDocumentLayout (as example: no scaling of images, when scaling the TextItem)?
Or there are the same issues?
----
Another question: you have a DIN A4 page in OpenOffice with text cursor, what could that be in QT a QGraphicsTextItem (or is this more a TextField in OpenOffice)?
Re: QImage inserted into QGraphicsTextItem looks fuzzy, when scaling QGraphicsTextIte
You can't set any "rules", you can only implement your own text layout. it is solely the layout's decision how it renders the document.
Re: QImage inserted into QGraphicsTextItem looks fuzzy, when scaling QGraphicsTextIte
And then the "image is fuzzy" problem will be solved?
Re: QImage inserted into QGraphicsTextItem looks fuzzy, when scaling QGraphicsTextIte
I have no idea, I don't even know what you are doing. I have a feint feeling you are trying to do something with a really bad approach.
1 Attachment(s)
Re: QImage inserted into QGraphicsTextItem looks fuzzy, when scaling QGraphicsTextIte
Now I will show what I'm doing...
See screenshot for details, there I have commented my idea.
(the handwritten text are multiple QGraphicsItem's, they have their own class GraphicsItem that including a QVector of QPointF's, and a painting method that draws the lines)
My program should be a alternative to Xournal, but with the feature to insert Math. Formulas...
Re: QImage inserted into QGraphicsTextItem looks fuzzy, when scaling QGraphicsTextIte
Look, if you insert an image into a text item, you insert a bitmap of specified dimensions. If you start scaling this item, the bitmap gets scaled too. If you scale the item up, the image will be scaled up as well and once its size starts getting larger than the size of the image inserted into the item, you'll start getting artifacts. If you operate on a static bitmap there is no workaround for that. If you use the image insertion variant that uses a QTextImageFormat either the default layout will try to generate proper bitmaps for you or you will be able to implement a custom text layout engine that will generate proper bitmaps depending on the area the whole document is to occupy. But still if the image source provides a bitmap smaller than the requested size, you'll be getting artifacts. Open Office probably generates an outline (vector) and not a bitmap so it can easily cope with this situation. If you are able to generate outlines (like (e)ps) for your math formulas, it will be trivial to solve the problem of a finite resolution of the bitmap.
Re: QImage inserted into QGraphicsTextItem looks fuzzy, when scaling QGraphicsTextIte
Quote:
If you are able to generate outlines (like (e)ps) for your math formulas, it will be trivial to solve the problem of a finite resolution of the bitmap.
I'm able to get a SVG of the formula, or PS could work, too.
But I'm think about, to replace LaTeX support to MathML support (http://doc.trolltech.com/solutions/4/qtmmlwidget/ , high_flyer made me watchful about the qtmmlwidget)
But qtmmlwidget is a widget, what's to do with that (have QGraphicsImageItem a inputWidget() method - I'm not aware that there is one)?
But all in all, the possibility to insert a png or jpeg image must given, it should possible to insert generic pictures (not formulas). And not of all pictures exist's a svg...
Quote:
(like (e)ps) for your math formulas, it will be trivial to solve the problem
Why is that so trivial?
Re: QImage inserted into QGraphicsTextItem looks fuzzy, when scaling QGraphicsTextIte
Quote:
Originally Posted by
stefan-koch
If you do that, you make your application dependent on Internet and availability of some webservice.
Quote:
Why is that so trivial?
Because vectors are mathematical entities, they don't have a resolution.
Re: QImage inserted into QGraphicsTextItem looks fuzzy, when scaling QGraphicsTextIte
Quote:
Because vectors are mathematical entities, they don't have a resolution.
How to insert SVG's or (E)PS in a QGraphicsTextItem?
http://doc.trolltech.com/4.7/richtext-textobject.html
With this example we get again a QImage...
How look's the trivial solution with SVG, EPS?
Re: QImage inserted into QGraphicsTextItem looks fuzzy, when scaling QGraphicsTextIte
Read my lips: there is no single function call you can make to obtain the goal you want. You'll have to get your hands dirty. The example you posted is a good start.
3 Attachment(s)
Re: QImage inserted into QGraphicsTextItem looks fuzzy, when scaling QGraphicsTextIte
So it works with QTextImageFormat
Code:
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);
}
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?
Re: QImage inserted into QGraphicsTextItem looks fuzzy, when scaling QGraphicsTextIte
QTextObjectInterface::draw() might be responsible for scaling the image.