Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QPainter drawText ignores last blank space in a multiple line string

QPainter drawText ignores last blank space in a multiple line string

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 606 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    wthung
    wrote on last edited by
    #1

    Hi guys,

    We have a customized QGraphicsItem which paints itself. However, in below code:

    QTextOption textOption;
    
    textOption.setWrapMode(QTextOption::WrapAnywhere);
    textOption.setAlignment(Qt::AlignRight);
    textOption.setFlags(QTextOption::IncludeTrailingSpaces);
    
    text = QString("Parameter \nSettings ");
    painter->drawText(rcText, text, textOption);
    

    The blank space after 'Parameter' is always ignored, but the one after 'Settings' is not ignored.
    User wants to get a little border when drawing the text. We know we can reduce the text rectangle to fulfill the request. But still want to know is there anyway to let Qt respect the blank space in first line? Tried many text options and flags but no one works.

    Thanks.

    jsulmJ 1 Reply Last reply
    0
    • W wthung

      Hi guys,

      We have a customized QGraphicsItem which paints itself. However, in below code:

      QTextOption textOption;
      
      textOption.setWrapMode(QTextOption::WrapAnywhere);
      textOption.setAlignment(Qt::AlignRight);
      textOption.setFlags(QTextOption::IncludeTrailingSpaces);
      
      text = QString("Parameter \nSettings ");
      painter->drawText(rcText, text, textOption);
      

      The blank space after 'Parameter' is always ignored, but the one after 'Settings' is not ignored.
      User wants to get a little border when drawing the text. We know we can reduce the text rectangle to fulfill the request. But still want to know is there anyway to let Qt respect the blank space in first line? Tried many text options and flags but no one works.

      Thanks.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @wthung Maybe adding Qt::TextIncludeTrailingSpaces helps?
      https://doc.qt.io/qt-5/qt.html#TextFlag-enum

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3
      • W Offline
        W Offline
        wthung
        wrote on last edited by
        #3

        @wthung said in QPainter drawText ignores last blank space in a multiple line string:

        QTextOption::IncludeTrailingSpaces

        @jsulm Tried QTextOption::IncludeTrailingSpaces but not work. QTextOption::IncludeTrailingSpaces has the same defined value as Qt::TextIncludeTrailingSpaces, so I think it does not work as well?

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved