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::draw() ingnores \n

QPainter::draw() ingnores \n

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 665 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.
  • QT-static-prgmQ Offline
    QT-static-prgmQ Offline
    QT-static-prgm
    wrote on last edited by
    #1

    Hi,

    i have a QString with a longer text that contains \n for new lines. The QLabel displays everything correctly. Now i want to save this text as pdf file. I tried Printing the QLabel, but that's not so good because of the resolution. So i thought the better way is to print the text directly instead of display it on a label and print that label.

    QPdfWriter pdfwriter("qtwritten.pdf");
    pdfwriter.setPageSize(QPageSize(QPageSize::A4));
    QPainter painter(&pdfwriter);
    
    painter.setFont(*m_font);
    painter.drawText(0, 0, "Hello\nworld!");
    

    The Result is 0_1541330039923_Unbenannt.JPG

    Any solution ideas? Or maybe alternatives to write the text to a pdf file?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Try

      painter->drawText(this->rect(), Qt::AlignCenter,"Hello\nworld!");
      

      We give it an area (rect) instead of x,y only

      1 Reply Last reply
      2

      • Login

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