Page 1 of 3 123 LastLast
Results 1 to 20 of 52

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

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

    Default QImage inserted into QGraphicsTextItem looks fuzzy, when scaling QGraphicsTextItem

    Hello,

    Look into the attachment: screenshot.png

    There is a problem with the "asdf" (QImage) in the QGraphicsTextItem: it is fuzzy. And that's because the QGraphicsTextItem is scaled with setScale(...).

    I scale the QGraphicTextItem, because I want zoom the text in/out later in the programm. And yet I zoom it because the text should have the correct size in millimeters.

    The text scaling works fine, but the "asdf" QImage will zoomed, too.

    How to insert a QImage with high resolution, and make it smaller with scaling that the QImage doesn't looks fuzzy?
    Or there other ways to solve this?

    (An idea is to get the HTML of the TextItem and multiplicate all font sizes with the zoom level. But is there a better way?)

    Thanks

    Stefan Koch
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

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

    How to insert a QImage with high resolution, and make it smaller with scaling that the QImage doesn't looks fuzzy?
    Just the same as you did, just make the QImage size larger, and scale it to the result size you need.

    But why don't you use QGraphicsTextItem?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

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

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

    I don't understand your question:
    But why don't you use QGraphicsTextItem?
    I use QGraphicsTextItem.

    ... make the QImage size larger, and scale it to the result size you need.
    How make a QImage size larger? Or: How to scale a QImage?

    In my situation I set the scale of the QGraphicsTextItem a. e. to 1.5 (I make it greater, not smaller)

    Thanks

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

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

    I use QGraphicsTextItem.
    But you are using QImage for the 'asd' text as well - why?
    I guess I don't understand what it is you are trying to do...

    How make a QImage size larger?
    QImage ( const QSize & size, Format format )
    QImage ( int width, int height, Format format )
    QImage scaled(...)
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

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

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

    I have tested now, insert a scaledToHeight() image into the QGraphicsTextItem, the image is now smaller, but always the same rendering problem.

    I have a QGraphicsTextItem with setScale it will be scaled.
    see setScale(x)
    if x<1
    it works
    if x>1
    the inserted image get's fuzzy, it will be automatically zoomed, without enough information, a. e. the image is 15x15 pixel, now it will be automatically zommed by QT to 20x20 but the informations are only in 15x15, so QT must interpolate. Is is it possible to insert a Image with 150x150 pixel and zoom it to 10% that are enought informations here, and that's no interpolating needed if scale the QGraphicsTextItem to 1.5 (something higher as 1) - that's my idea of the problem - this idea could wrong


    P. S. : I insert the image with a QTextCursor (cursor->insertImage(...))
    Last edited by stefan-koch; 16th November 2010 at 13:26.

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

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

    I still fail to understand why you are using a QImage... what is it for?
    Why not just let QGarphicsTextItem do the text rendering?
    It will scale it correctly too!

    Be as it may to your question:
    Is is it possible to insert a Image with 150x150 pixel and zoom it to 10%
    Yes as I said before, I probably just don't understand again - where is the problem?
    Create the QImage 150x150 and scale it down to 15x15... You know how to create QImage which is 150x150, and you know how to scale it... so I don't see where is the problem?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

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

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

    Why not just let QGarphicsTextItem do the text rendering?
    I have added a new screenshot to this answer, I hope this screenshot says all.
    (Or is QGraphicsTextItem able to render LaTex?)

    The third small image is the scaledToHeight(10) Image, it's fuzzy too.

    The original sqrt-Image the alonestanding sqrt-png-file.


    Added after 8 minutes:


    The unscaled QGraphicsTextItem is also attached as png-File (here is a red Text included, that says that this is unscaled)
    Attached Images Attached Images
    Last edited by stefan-koch; 16th November 2010 at 16:51.

  8. #8
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

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

    I see.
    Try turning anti aliasing off if its on and see if it helps.

    (Or is QGraphicsTextItem able to render LaTex?)
    QGraphicsTextItem probably doesn't render LaTex, but you might find this interesting:
    http://doc.trolltech.com/solutions/4/qtmmlwidget/
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

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

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

    Hello,

    now I have disabled setRenderHint(QPainter::SmoothPixmapTransform) in QGraphicsView.
    Antialiasing is not enabled in QGraphicsView.

    See screenshot for details.

    What's the problem?

    Thanks
    Attached Images Attached Images

  10. #10
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

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

    Hmm... I think this is just a scaling artifact. You don't see that with the text object (probably) because it really does render the text when scaled - and probably the line width is not as thin as it should be but a width that looks good at that size , but your QImage is just scaling it, making the lines thiner and when they are near each other you see the difference.
    But that is just a guess.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

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

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

    What mean you with "lines"?

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

    Did you enable smooth image transformations for your view?
    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.


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

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

    @wysota
    Do you mean this: setRenderHint(QPainter::SmoothPixmapTransform)
    it was enabled in QGraphicsView in post #7 (see screenshot for details)

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

    In general your image is of a very poor quality. The Nyquist law is merciless here.
    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.


  15. #15
    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 does not work at all.
    I have made a little test project. A MainWindow with a GraphicsView. I add the source code, if you want you can test it on your own computer (unzip the attachment TextItemTest.zip and compile it).

    Note the attachment tex.png must be saved in your home folder (/home/<USER> on Linux).

    And the third attachment shows you the screenshot of the little text project, including fuzzy sqrt-5 image NOW with 3600 dpi! (scaled to height 30 pix)

    Thanks

    A little code cutting form the test project:
    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(dir.absoluteFilePath("tex.png"));
    18. QImage imageScaled = image.scaledToHeight(30, Qt::SmoothTransformation);
    19. //QImage imageScaled = image.scaledToHeight(30);
    20.  
    21. textItem->textCursor().insertImage(imageScaled);
    22.  
    23. textItem->setScale(3);
    24.  
    25. ui->graphicsView->scene()->addItem(textItem);
    26. }
    To copy to clipboard, switch view to plain text mode 

    P. S. set scale to 1 instead of 3 and it works fine
    How is it possible to reply in a new post not by editing my old post (if nobody answered first)????
    Attached Images Attached Images
    Attached Files Attached Files

  16. #16
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

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

    Wait a minute...
    Qt Code:
    1. textItem->textCursor().insertImage(imageScaled);
    2.  
    3. textItem->setScale(3);
    To copy to clipboard, switch view to plain text mode 
    No wonder you get poor quality!
    You put your DOWN scaled image, and scale it up x3 !!
    You should do it so:
    Qt Code:
    1. QImage image(dir.absoluteFilePath("tex.png"));
    2. QImage imageScaled = image.scaledToHeight(30, Qt::SmoothTransformation);
    3.  
    4. textItem->setScale(3);
    5.  
    6. textItem->textCursor().insertImage(imageScaled);
    To copy to clipboard, switch view to plain text mode 
    You have to scale DOWN your LARGE image not UP the SMALL image!
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

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

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

    Is the only change to my code to swap the lines 23. and 25. from post #15?

    I can't see any change in your code improvement, as that you have swapped these lines, right?

    Now the new code, with exactly the same issue:

    What went wrong?
    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(dir.absoluteFilePath("tex.png"));
    18. QImage imageScaled = image.scaledToHeight(30, Qt::SmoothTransformation);
    19. //QImage imageScaled = image.scaledToHeight(30);
    20.  
    21. textItem->setScale(3);
    22.  
    23. textItem->textCursor().insertImage(imageScaled);
    24.  
    25. ui->graphicsView->scene()->addItem(textItem);
    26. }
    To copy to clipboard, switch view to plain text mode 

  18. #18
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

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

    Hmm... I don't know.

    If you take your original large image, and scale it to 30 in an image editing application, does it look the same as the one you get with your code?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

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

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

    Yes, exactly.

    See screenshot in this thread (test1.png).

    I add the source code of the project (all headers, all cpps, ui-file, ...) this will be found in the TextItemTest.zip attachment of this thread. If you want you can test it on your own pc.

    I add the tex.png, the 3600 dpi sqrt-5 file, too (to this thread).

    Thanks.
    Attached Images Attached Images
    Attached Files Attached Files

  20. #20
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

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

    Yes, exactly.
    What yes exactly?
    The image the edit application gets is the same results as your scaling in the application?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

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