Results 1 to 3 of 3

Thread: How can I scale all the fonts in a QTextDocument

  1. #1
    Join Date
    Sep 2014
    Posts
    27
    Thanks
    2
    Thanked 2 Times in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default How can I scale all the fonts in a QTextDocument

    So I have a tricky problem that I need an efficient solution to. I need to be able to apply a product-wide zoom to my application. That part isn't too hard, everything gets font sizes from the application style sheet, or asks a helper class for its font, so I can just scale those up based on a zoom factor.

    The problem is that I have text fields and tables where the user is able to alter font sizes, and they can apply a larger font to individual words/characters. So is there any simple way that I can maybe change the scaling factor for point size fonts or something?

    The solution I can see is scanning through the various QTextDocuments when they are painted and watch for where the font size changes and alter the document. It seems like this would be expensive though.

    Any ideas from the community?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How can I scale all the fonts in a QTextDocument

    Are you using QTextView or QTextBrowser for display? Sounds like QTextView::zoomIn() and QTextView::zoomOut() already do what you want.

    Otherwise, can you override the paintEvent() for your view class and apply a scale transform before passing the paintEvent up to the base class?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Sep 2014
    Posts
    27
    Thanks
    2
    Thanked 2 Times in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How can I scale all the fonts in a QTextDocument

    We are using classes that derive from QTextEdit for our editors, but it doesn't seem like QTextEdit::zoomIn() is doing what I would expect it to do. The zoom functions work fine for unformatted text, but if I apply a font size to my text then zoom in doesn't appear to actually do anything.

    For example: I have the following text string saved for one of the table indexes:

    "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:5pt;\">test</span><span style=\" font-size:15pt;\">test</span></p>"
    When that html is set to the editor and I then apply zoomIn(5), the point size appears to be unaffected.

Similar Threads

  1. How to scale Qt fonts and screen for target device
    By embeddedlinuxer in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 14th October 2016, 11:31
  2. Replies: 1
    Last Post: 9th September 2013, 08:50
  3. Adding Arabic fonts and CJK (China Japan Korean) fonts
    By kishore7771 in forum Qt Programming
    Replies: 0
    Last Post: 30th July 2013, 19:33
  4. Replies: 2
    Last Post: 26th December 2012, 02:03
  5. Can't scale down fonts below 9pt in Linux
    By wysota in forum General Discussion
    Replies: 0
    Last Post: 18th January 2009, 13:43

Tags for this Thread

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.