Results 1 to 3 of 3

Thread: Scale centered text

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2011
    Posts
    25
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Scale centered text

    Hi all, I want to use the scale property of a Text so that the enclosed text shows up in its entirety (no wrap) within the size of the Text itself.
    I’d like to be able to operate directly on the scale property instead of changing the font size.

    Everything works, as long as the text is left-aligned. If I switch the text alignment to center, the text box appears in the right place, but the text is not center-aligned.
    I tried to change the transformOrigin to “Item.Center”, but this does not solve the problem.

    Attached you can find an example featuring a text and a rectangle enclosing it:
    Qt Code:
    1. Rectangle
    2. {
    3. id: rect
    4. anchors.fill: testText
    5. color: "yellow"
    6. }
    7.  
    8. Text
    9. {
    10. id: testText
    11.  
    12. width: 100
    13. height: 50
    14.  
    15. anchors.centerIn: parent
    16.  
    17. text: "example"
    18. verticalAlignment: Text.AlignVCenter
    19. horizontalAlignment: Text.AlignHCenter
    20.  
    21. scale: Math.min((width / paintedWidth), (height / paintedHeight))
    22. transformOrigin: Item.Center // <- I've tried every point...
    23. color: "black"
    24. }
    To copy to clipboard, switch view to plain text mode 

    here you can see the (wrong) result: http://i59.tinypic.com/29c9ymg.jpg

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Scale centered text

    Have you tried without the alignment properties? The anchor setting should already take care of the centering.

    Cheers,
    _

Similar Threads

  1. drawPoint not centered
    By Alundra in forum Qt Programming
    Replies: 1
    Last Post: 3rd November 2013, 07:38
  2. Scale Image centered
    By metRo_ in forum Qt Programming
    Replies: 2
    Last Post: 23rd August 2010, 20:25
  3. Bar Chart centered on Labels
    By liversedge in forum Qwt
    Replies: 1
    Last Post: 30th January 2010, 19:57
  4. Why QFileDialog::getOpenFileName is not centered?
    By ricardo in forum Qt Programming
    Replies: 20
    Last Post: 30th August 2009, 23:08
  5. centered text label
    By djconnel in forum Qwt
    Replies: 5
    Last Post: 28th April 2009, 17:22

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.