Results 1 to 4 of 4

Thread: QFontMetrics not giving proper dimension

  1. #1
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Question QFontMetrics not giving proper dimension

    Hello,
    My problem is that QFontMetrics is not returning proper widths and heights of text in my program. I verified this by printing all text info of word "hello" in sample separate program and main program too.
    The sample works properly and it was manually compiled with g++ while the other doesn't.

    While in the sample , the info read
    Family=Sans Serif, Point Size = 11, Width of hello = 33
    the info from my original app read
    Family=Sans Serif, Point Size = 11, Width of hello = 24

    And also, though I have commented *.setFont() , resize() and other geometry functions ,i still get same problem described above.
    Because of this, my app looks very ugly with truncations and variations in font sizes in all used Qt widgets .

    Is there any chance that the ordering of libs being linked is causing trouble ?

    I tried all programs described above with Qt 4.1, and 2 snapshots of QT 4.2 on my linux system. (g++ 4.0.2)

    Actually i had posted my problem in more vague form before in this thread http://www.qtcentre.org/forum/f-qt-p...ides-3874.html
    Later i really tried hard to figure out the problem and noticed that it was all to do with QFontMetrics.

    Please do help me solve this problem.
    Thanks in advance.
    Last edited by Gopala Krishna; 6th October 2006 at 16:16. Reason: Forgot to add an impt info

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFontMetrics not giving proper dimension

    Do you have any static data in your application (esp. QFont instances)?

  3. #3
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QFontMetrics not giving proper dimension

    Hello Jacek,
    Thanks for the hint. Problem detected and solved !!
    Thank you very much !!

    Do you have any static data in your application (esp. QFont instances)?
    Yes, there was a qfont instance wrapped in a global struct (but not static explicitly) but the structure was declared before main(). I just commented the QFont entries and then a MAGIC - it worked properly.

    Can you enlighten me why this happens ? What other classes in qt can cause problems when declared static (or global too) ?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFontMetrics not giving proper dimension

    Quote Originally Posted by Gopala Krishna View Post
    Can you enlighten me why this happens ?
    Qt uses some 3rd party libraries to handle fonts and they might require some initialization and this usually happens when you create Q(Core)?Application instance.

    Quote Originally Posted by Gopala Krishna View Post
    What other classes in qt can cause problems when declared static (or global too) ?
    I would suspect these classes and methods:
    • QCoreApplication::application*Path()
    • QApplication::desktop()
    • QApplication::palette()
    • QFont
    • QFontDatabase
    • QLibraryInfo
    • QWidget
    • QX11Info

    There was also some problem with QObject, but AFAIR it was resolved.

    The best way is to avoid global variables and to initialize static variables after the main was invoked.

  5. The following user says thank you to jacek for this useful post:

    Gopala Krishna (7th October 2006)

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.