Page 1 of 2 12 LastLast
Results 1 to 20 of 26

Thread: Text does not drawn properly in RTOL locale on Mac OS X

  1. #1
    Join Date
    Jul 2007
    Posts
    90
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Text does not drawn properly in RTOL locale on Mac OS X

    Hi all,

    I am facing very strange problem with the behavior of QPainter::drawText in RTOL locale on Mac OS X.

    If i draw any text by providing bounding rect and specifying the alignment like drawText( rt, Qt::AlignLeft, text), it does not drawn properly.

    ANy one knows why this is happening?


    Thanks in advance.

    regards,
    ~Sanjay

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

    Default Re: Text does not drawn properly in RTOL locale on Mac OS X

    What does "not drawn properly" mean in this case?
    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. #3
    Join Date
    Jul 2007
    Posts
    90
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Text does not drawn properly in RTOL locale on Mac OS X

    I have customized QGraphicsItem to draw the custom fractions like "1000 1/2".
    SO in RTOL locale this fraction should be displayed as "1/2 1000".
    In Paint() i written code to draw the 1000 to the left of the bounding rect and 1/2 to the right of the bounding rect.
    This is working properly on Windows in RTOL or LTOR locale.

    But on Mac OS X these texts are getting overlapped on each other in RTOL locale.

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

    Default Re: Text does not drawn properly in RTOL locale on Mac OS X

    Can we see the code?
    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. #5
    Join Date
    Jul 2007
    Posts
    90
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Text does not drawn properly in RTOL locale on Mac OS X

    I have attached the sources. please have a look.
    Attached Files Attached Files

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

    Default Re: Text does not drawn properly in RTOL locale on Mac OS X

    To me it seems the layout of text has nothing to do with the effect you get. As you are drawing everything yourself, Qt can't decide on anything. The only thing it could do (I don't say it does) is to reverse the meaning of right and left when calling QPainter::drawText() but this is easy to check - simply reverse the flag in your code when doing RTOL on a Mac and see if it helps. If it's still wrong then you're probably calculating positions incorrectly. It also depends on what "overlapping" means in your case.
    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. #7
    Join Date
    Jul 2007
    Posts
    90
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Text does not drawn properly in RTOL locale on Mac OS X

    I tried with reversing the flag in the code when doing RTOL on a Mac, but it does not work.
    The text gets overlapped means
    1/2
    and
    1000
    gets overlapped.

    i guess there is problem while drawing text with the alignment flags on Mac OS X in RTOL locale.

    As far as their positions are concerned their calculations are straightforward. I dont think so there is any problem.

    The most notable thing is that this works fine on windows. I agree that the windows architecture is different but then the question is this problem should be there on windows for RTOL if the calculation is wrong.

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

    Default Re: Text does not drawn properly in RTOL locale on Mac OS X

    Quote Originally Posted by sanjayshelke View Post
    The text gets overlapped means and gets overlapped.
    Yes, that explains a lot

    Are they drawn in exactly the same place or does only parts cover the same region? Maybe you could post a screenshot?
    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. #9
    Join Date
    Jul 2007
    Posts
    90
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Text does not drawn properly in RTOL locale on Mac OS X

    Sorry that was a typo mistake.

    I have attached two screen shots for your reference. One screen shot contains overlapped text and other is required text.


    Please have a look
    Attached Images Attached Images

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

    Default Re: Text does not drawn properly in RTOL locale on Mac OS X

    To me it seems your item may simply be too narrow. Try increasing the boundingRect() and see if it changes anything.
    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. #11
    Join Date
    Jul 2007
    Posts
    90
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Text does not drawn properly in RTOL locale on Mac OS X

    Increasing the bounding rect does solve my problem.
    BUt then this is the incorrect way to fix this issue. I am just finding out why this is been incorrect in RTOL locale.

    If you can see the implementation of boundingRect() of this item, it has been implemented properly as far as my knowledge is concerned.

    see this :
    Qt Code:
    1. QRectF QFractionTextItem :: boundingRect()const
    2. {
    3. return QRectF( 0, 0 ,m_nWidth, m_nHeight*2 );
    4. }
    To copy to clipboard, switch view to plain text mode 

    where m_nWidth is the addition of QFontMetrics::width("1000") and qMax( QFontMetrics::width("1") , QFontMetrics::width("2") )

    SO i am just wondering what is going wrong behind the screen.

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

    Default Re: Text does not drawn properly in RTOL locale on Mac OS X

    Quote Originally Posted by sanjayshelke View Post
    BUt then this is the incorrect way to fix this issue.
    True. The correct way is to fix your code which apparently computes the bounding rect incorrectly.

    where m_nWidth is the addition of QFontMetrics::width("1000") and qMax( QFontMetrics::width("1") , QFontMetrics::width("2") )
    Maybe there is some margin somewhere? Try adding this code to your paint():

    Qt Code:
    1. painter->save();
    2. painter->setPen(Qt::red);
    3. painter->drawRect(boundingRect());
    4. painter->restore();
    To copy to clipboard, switch view to plain text mode 

    Also you don't tell the item that its bounding rect changes when you change the font. You should call prepareGeometryChange() after setting the font.
    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
    Jul 2007
    Posts
    90
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Text does not drawn properly in RTOL locale on Mac OS X

    I tried this option of drawing rectangle around its bounding rect, but there is no margin.

    The most important thing i like to point out that if you draw the text by specifying the x and y pos( do not provide rectt and alignment while drawing text ), it does draws the text properly without getting overlapped on each other.

    But even though i have implemented the boundingRect() method correctly, it clips some part of the text from outside.

    here are some points i have highlighted
    1.QFontMetrics is not working properly and hence giving incorrect width of the text
    2.boundingRect() is incorrect ( which looks like the root cause but its implemenation is very straight forward and correct )
    3.QPainter::drawText() with the parameter rect and alignment flags behaves incorrectly in RTOL locale on Mac. ( this is sure a Qt bug )

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

    Default Re: Text does not drawn properly in RTOL locale on Mac OS X

    (1) is impossible - it wouldn't work in many other cases as well and apparenty it does work otherwise every output in Qt would be a mess
    (2) may only be your own fault
    (3) is possible although if I were you I would refrain from using the word "surely" until you look at source code of the method and prove it is a bug. Right now I am closer to proving it is not a bug in Qt than you are to proving it is. At least I have taken a look into the source code and I can say there is no ifdef for mac in code responsible for drawing the text through your method.
    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
    Jul 2007
    Posts
    90
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Text does not drawn properly in RTOL locale on Mac OS X

    ok. I agreed that i have not taken a look on the methods i have used. I do not have a source code of Qt. I will take it first.
    But then i am still unable to find out the cause of this weird behavior.
    What you suggest ion this?

  16. #16
    Join Date
    Jul 2007
    Posts
    90
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Text does not drawn properly in RTOL locale on Mac OS X

    Based on the points i have highlighted i troubleshoot the issue.
    Further debugging the issue i could found some fruitful observations.
    Observation are:

    font used in the class is "Comic Sans Ms" and point size is 18
    1.in LTOR locale
    QFontMetrics::width("1000") returns 41 value
    QFontMetrics::width("900") returns 33 value
    QFontMetrics::width("90") returns 22 value

    2.in RTOL locale
    QFontMetrics::width("1000") returns 30 value
    QFontMetrics::width("900") returns 22 value
    QFontMetrics::width("90") returns 22 value


    it looks that QFontMetrics::width() gives incorrect values on Mac OS X in RTOL locale.

    You can also try out this by just drawing "1000" in your customized QGraphicsItem on Mac OS X in RTOL and LTOR locale. Just drawing text "1000" gets clipped.

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

    Default Re: Text does not drawn properly in RTOL locale on Mac OS X

    Did you try other fonts as well? Maybe the font itself is broken...
    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.


  18. #18
    Join Date
    Jul 2007
    Posts
    90
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Text does not drawn properly in RTOL locale on Mac OS X

    Yes i have tried with other fonts also. But the problem still exist.

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

    Default Re: Text does not drawn properly in RTOL locale on Mac OS X

    Run one of existing Qt applications (like Designer) with the -reverse parameter. See if widths of text (especially in message boxes where the texts are long) got screwed up.
    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.


  20. #20
    Join Date
    Jul 2007
    Posts
    90
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Text does not drawn properly in RTOL locale on Mac OS X

    Which message box your talking about in designer app? Can you please elaborate?
    I can see none of the text displayed on designer app is screwed up.

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. HTML text drawn with QPainter::drawText()
    By MarkoSan in forum Qt Programming
    Replies: 1
    Last Post: 19th January 2008, 01:23
  3. Replies: 1
    Last Post: 12th November 2006, 16:56

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
  •  
Qt is a trademark of The Qt Company.