Page 3 of 3 FirstFirst 123
Results 41 to 52 of 52

Thread: QImage inserted into QGraphicsTextItem looks fuzzy, when scaling QGraphicsTextItem

  1. #41
    Join Date
    Nov 2010
    Posts
    26
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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)?

  2. #42
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #43
    Join Date
    Nov 2010
    Posts
    26
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QImage inserted into QGraphicsTextItem looks fuzzy, when scaling QGraphicsTextIte

    And then the "image is fuzzy" problem will be solved?
    Last edited by stefan-koch; 20th November 2010 at 17:30.

  4. #44
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #45
    Join Date
    Nov 2010
    Posts
    26
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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...
    Attached Images Attached Images
    Last edited by stefan-koch; 20th November 2010 at 18:47.

  6. #46
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #47
    Join Date
    Nov 2010
    Posts
    26
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QImage inserted into QGraphicsTextItem looks fuzzy, when scaling QGraphicsTextIte

    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...

    (like (e)ps) for your math formulas, it will be trivial to solve the problem
    Why is that so trivial?
    Last edited by stefan-koch; 20th November 2010 at 18:40.

  8. #48
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QImage inserted into QGraphicsTextItem looks fuzzy, when scaling QGraphicsTextIte

    Quote Originally Posted by stefan-koch View Post
    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)
    If you do that, you make your application dependent on Internet and availability of some webservice.

    Why is that so trivial?
    Because vectors are mathematical entities, they don't have a resolution.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #49
    Join Date
    Nov 2010
    Posts
    26
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QImage inserted into QGraphicsTextItem looks fuzzy, when scaling QGraphicsTextIte

    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?

  10. #50
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #51
    Join Date
    Nov 2010
    Posts
    26
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QImage inserted into QGraphicsTextItem looks fuzzy, when scaling QGraphicsTextIte

    So it works with QTextImageFormat

    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6. QDir dir;
    7. dir.cd(QDir::homePath());
    8.  
    9. ui->graphicsView->setRenderHint(QPainter::SmoothPixmapTransform);
    10. ui->graphicsView->setRenderHint(QPainter::Antialiasing);
    11.  
    12. ui->graphicsView->setScene(scene);
    13.  
    14. textItem->setTextInteractionFlags(Qt::TextEditorInteraction);
    15. textItem->setPlainText("test");
    16.  
    17. QImage *image = new QImage(dir.absoluteFilePath("tex.png"));
    18.  
    19. QTextDocument *document = textItem->document();
    20. document->addResource(QTextDocument::ImageResource,QUrl::fromLocalFile(dir.absoluteFilePath("tex.png")),*image);
    21.  
    22. QTextImageFormat imageFormat;
    23. imageFormat.setName(dir.absoluteFilePath("tex.png"));
    24. imageFormat.setHeight(30);
    25.  
    26. textItem->setScale(4);
    27.  
    28. textItem->textCursor().insertImage(imageFormat);
    29.  
    30. ui->graphicsView->scene()->addItem(textItem);
    31. }
    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?
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by stefan-koch; 26th November 2010 at 13:29.

  12. #52
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QImage inserted into QGraphicsTextItem looks fuzzy, when scaling QGraphicsTextIte

    QTextObjectInterface::draw() might be responsible for scaling the image.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QGraphicsTextItem - setHTML()
    By Claymore in forum Qt Programming
    Replies: 7
    Last Post: 17th September 2009, 09:34
  2. QGraphicsRectItem and QGraphicsTextItem.
    By cydside in forum Qt Programming
    Replies: 13
    Last Post: 20th July 2009, 12:11
  3. QGraphicsTextItem in a Widget ,Is it Possible ??
    By salmanmanekia in forum Qt Programming
    Replies: 10
    Last Post: 28th July 2008, 13:45
  4. QValidator for QGraphicsTextItem
    By arjunasd in forum Qt Programming
    Replies: 4
    Last Post: 8th August 2007, 15:34
  5. QGraphicsTextItem - is it a bug there?
    By Tair in forum Qt Programming
    Replies: 5
    Last Post: 18th October 2006, 08:48

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.