Results 1 to 12 of 12

Thread: Font is scaled

  1. #1
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Font is scaled

    Parent item has a scale transform set, the child item's font is automatically scaled. How can I drawText with orignal font (without scaling from parent) at the same location?

    Thanks
    Last edited by lni; 29th January 2009 at 20:34.

  2. #2
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Font is scaled

    Anyone help pls?

  3. #3
    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: Font is scaled

    Use QGraphicsItem::ItemIgnoresTransformations

  4. #4
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Font is scaled

    Quote Originally Posted by wysota View Post
    Use QGraphicsItem::ItemIgnoresTransformations
    Try this and it is not desirable. The text is now drawn in the wrong place...

    I can use QPen::setCosmetic, I think QFont should have similar property. When doing transform, most of the time we want to keep the font size unchanged...

    By the way, setScalable or setTransformable is much more intuitive...

  5. #5
    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: Font is scaled

    Quote Originally Posted by lni View Post
    Try this and it is not desirable. The text is now drawn in the wrong place...
    You're on your own then.

  6. #6
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Font is scaled

    This is terrible, I have spent 6 hours on this and found nothing!

    All I want is not to rotate or scale my font. QGraphicsItem::ItemIgnoresTransformations does ignore the scaling and rotating, but it also lose the location.

    Can some one please give an example?

  7. #7
    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: Font is scaled

    If you set the bounding rect of the text item correctly, you won't lose position, just anchor the (0,0) point to the position where you want it to be.

  8. #8
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Font is scaled

    Quote Originally Posted by wysota View Post
    If you set the bounding rect of the text item correctly, you won't lose position, just anchor the (0,0) point to the position where you want it to be.
    I am trying to print the grid number along axis, such as 0, 10, 20, 30.... This GridNumberTextItem is derived from QGraphicsItem, so here is what I do
    Qt Code:
    1. GridNumberTextItem::GridNumberTextItem(...)
    2. {
    3. setFlag( QGraphicsItem::ItemIgnoresTransformations );
    4. }
    5.  
    6. GridNumberTextItem::paint(...)
    7. {
    8. float val = 0;
    9. while ( val <= 100 ) {
    10. QPointF pos( val, 0 ); // <=== lose the trasform from the parent
    11. painter->drawtext( pos, QString::number( val ) );
    12. val += 10; // assuming step is 10
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 

    In doing so, I lose transform for "pos", so the text is drawn in wrong place. The parent item has a scaling transform. How can I fix this problem? Thanks!

  9. #9
    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: Font is scaled

    I'm not sure why you use some "pos" inside your paint routine. You should anchor the text item to the value you want it to represent. Then you can make it ignore transformations and rely purely on setPos().

  10. #10
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Font is scaled

    Quote Originally Posted by wysota View Post
    I'm not sure why you use some "pos" inside your paint routine. You should anchor the text item to the value you want it to represent. Then you can make it ignore transformations and rely purely on setPos().
    Do you mean I need to create many QGraphicsSimpleTextItem, with each item anchoring one grid point? If it is, then what if I have a million grid points? If not, can you give example or be more specific on how to do it?

    Many thanks!

  11. #11
    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: Font is scaled

    Quote Originally Posted by lni View Post
    Do you mean I need to create many QGraphicsSimpleTextItem, with each item anchoring one grid point? If it is, then what if I have a million grid points?
    We were talking about fonts here so I more meant the labels describing points. And yes, I meant make each label a separate item.

    I'm not exactly sure what you are doing - it is probably some kind of graph or canvas and a ruler. Have you thought about making the ruler a separate widget?

  12. #12
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Font is scaled

    Quote Originally Posted by wysota View Post
    We were talking about fonts here so I more meant the labels describing points. And yes, I meant make each label a separate item.

    I'm not exactly sure what you are doing - it is probably some kind of graph or canvas and a ruler. Have you thought about making the ruler a separate widget?
    I will investigate the separate widget option then...

    Yes, it is for graph plot - to plot, for instance, time vs. temperature, and I need to label the X-axis (50, 60, 70, ...) and Y-axis (2.1, 2.2, 2.3, 2.4...). Making each tick as a separated item is too much in this case. I have been using Qt for some time, but only last week I discovered QGraphicsItem, so it is quite new to me, if you can point me to some correct direction, I would very much appreciate...I have run all the examples in the graphics section though...

    But if you can provide QFont::Cosmetic, just like QPen, life would be much much easier...

    It is similar to the one below. As you can see, if I zoom in, it look ugly if the label text get scaled, especially if I zoom it with different scale in X and Y, the label is totally distorted, which brings no value to the users...

    ,

Similar Threads

  1. font can not be changed
    By ashishsaryar in forum Qt Programming
    Replies: 4
    Last Post: 28th May 2008, 15:32
  2. Font size calculation when painting in a QImage
    By Ishark in forum Qt Programming
    Replies: 3
    Last Post: 15th July 2007, 22:22
  3. Automatic font selection
    By NTwoO in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 27th April 2007, 12:40
  4. Font not Antialiasing
    By ChasW in forum Qt Programming
    Replies: 6
    Last Post: 21st January 2007, 18:12
  5. Qt renders wrong font
    By durbrak in forum Qt Programming
    Replies: 8
    Last Post: 2nd November 2006, 14:36

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.