Results 1 to 4 of 4

Thread: Problems with StyleSheet and QFontMetrics (see attached program)

  1. #1
    Join Date
    Aug 2008
    Posts
    60
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Problems with StyleSheet and QFontMetrics (see attached program)

    Hi,

    Herewith I have attached a toy program in which it sets the stylesheet "* { font-size: 20pt; }" of app context.

    After setting above style sheet, I am taking QFontMetrics to do some processing on fontmetrics.width() / fontmetrics.height() but both are getting wrong.

    In toy program if you click "Print Font Info" button, I displays the correct information.
    But when showing the fontmetrics of dialog (click on 'Show Dialog') or panel (click on 'Show Panel') it displays wrong.

    In short: my aim is to set application font and subsequently I should get the correct fontmetrics info.

    Please let me know if I am doing anthing wrong.

    Thank you.
    -Hiral
    Attached Files Attached Files

  2. #2
    Join Date
    Aug 2008
    Posts
    60
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Problems with StyleSheet and QFontMetrics (see attached program)

    It seems that QFontMetrics takes effect only after showing widget.

    I moved some of the print statmenets (which prints the QFontMetrics info) after widget has been shown; and observed that it reflects the correct size.

    But still, my requirement is not met. I am using QFontMetrics inside the custom Widget's constructors to place/adjust widgets and which gives me incorrect sizes...
    Please help.

    Thank you.

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problems with StyleSheet and QFontMetrics (see attached program)

    Just put the code from the constructor into a function and call that function using QTimer::singleShot().
    This way when you use QFontMetrics, the widget will be shown and proper values available.

  4. #4
    Join Date
    Aug 2008
    Posts
    60
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Problems with StyleSheet and QFontMetrics (see attached program)

    Hi aamer4yu,

    Thank you for your suggesion.

    BTW: I did some experiments (with code inside the constructors) and found that if we call the minimumSizeHint() before taking QFontMetrics info then it given correct values !!! Thi is strange !!!
    Any idea why is this required ???

    Thank you.

Similar Threads

  1. Stylesheet and QFontMetrics
    By ucomesdag in forum Qt Programming
    Replies: 7
    Last Post: 18th January 2010, 07:45
  2. QFontMetrics.height()
    By Caius Aérobus in forum Qt Programming
    Replies: 8
    Last Post: 4th April 2009, 17:36
  3. Replies: 2
    Last Post: 26th March 2009, 08:43
  4. QFontMetrics and HTML tags
    By vonCZ in forum Newbie
    Replies: 1
    Last Post: 14th August 2008, 12:13
  5. QFontMetrics, i can't understand
    By pakulo in forum Qt Programming
    Replies: 11
    Last Post: 24th June 2007, 17:59

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.