Results 1 to 6 of 6

Thread: Right justify QPainterPath addText

  1. #1
    Join Date
    Aug 2008
    Location
    Texas, USA
    Posts
    44
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Right justify QPainterPath addText

    Hello,

    I'm using QPainterPath to draw my text so I can get nice outlined text that gets displayed over video. I'm using the addText(...) function and then the QPainter::drawPath.

    Some of my text I would like to have right justified instead of left justified. Is this possible? Any other suggestions?

    I want it to be outlined or stroked text so it has a 1 pixel black board around the white text otherwise I would just use the QPainter::drawText(...) function.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Right justify QPainterPath addText

    Did you try the alignment flags?
    http://doc.trolltech.com/4.7/qpainter.html#drawText
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Aug 2008
    Location
    Texas, USA
    Posts
    44
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Right justify QPainterPath addText

    No, what I'm saying is, from my web searching is that the only way I can get pixel stroked text is by using a QPainterPath and using addText and NOT drawText...

    addText does not have the alignment flags.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Right justify QPainterPath addText

    oops sorry, reading to fast.

    Hmm... since you are not using drawText() you probably will have to justify your self.
    But that should be rather easy - you have your paths bounding rect, so all you have to do is translate to "widget right edge" - "path_bounding_rect".
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Aug 2008
    Location
    Texas, USA
    Posts
    44
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Right justify QPainterPath addText

    Ahhh, very good idea.

    I just have one more question. It doesn't seem like there is a way to clear the elements from the QPainterPath.

    For example I have like 10 lines of text I would like to right justify. I would like to addText(...) get the bounding rect for that text and then translate the Painter path for each line. However there is no QPainterPath::clear() function. Does that mean I really need to construct a new QPainterPath object for each line? Seems kind of silly. What am I missing

    Thanks

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Right justify QPainterPath addText

    Currently from what I see in the docs you have to go the "long way".
    But I don't think constructing a new path for each string is really more expensive than adding text to existing path, as addText() creates sub paths.
    You think "text" but in reality this is just a bunch of paths - and you usually construct your path and draw it (fire and forget sort of), and not (re)use it like you (want to) do.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. QPainterPath and QPolygon
    By Muz in forum Qt Programming
    Replies: 0
    Last Post: 18th September 2009, 07:16
  2. right justify toolbar
    By magland in forum Qt Programming
    Replies: 5
    Last Post: 16th April 2008, 18:36
  3. How to right-justify QLabel text
    By JimDaniel in forum Qt Programming
    Replies: 2
    Last Post: 30th January 2008, 08:55
  4. QLCDNumber justify
    By davisjamesf in forum Qt Programming
    Replies: 1
    Last Post: 5th July 2007, 10:02
  5. QTextEdit Justify align making work
    By dec0ding in forum Qt Programming
    Replies: 2
    Last Post: 13th January 2006, 12:02

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.