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. How to get the string list divided by QPainter with Qt::TextWordWrap?
Forum Updated to NodeBB v4.3 + New Features

How to get the string list divided by QPainter with Qt::TextWordWrap?

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 186 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.
  • T Offline
    T Offline
    TomNow99
    wrote on last edited by TomNow99
    #1

    Hi,

    I have a long QString and I would like to know how, QPainter with Qt::TextWordWrap will divide it.

    For example. When I do ( pseudocode ):

    QString myText = "this is veeeeery, veeeeeery long string."
    QPainter painter(someImage);
    painter.drawText(QRect(0,0,100,100), Qt::TextWordWrap, myText);
    

    I see on the screen that I have myText divided like:
    first line = this is veeeeery, and second line = veeeeeery long string..

    So I need a function like:
    QStringList getStringListWhenWordWrap(QRect(0,0,100,100), myText, font);

    Christian EhrlicherC 1 Reply Last reply
    0
    • T TomNow99

      Hi,

      I have a long QString and I would like to know how, QPainter with Qt::TextWordWrap will divide it.

      For example. When I do ( pseudocode ):

      QString myText = "this is veeeeery, veeeeeery long string."
      QPainter painter(someImage);
      painter.drawText(QRect(0,0,100,100), Qt::TextWordWrap, myText);
      

      I see on the screen that I have myText divided like:
      first line = this is veeeeery, and second line = veeeeeery long string..

      So I need a function like:
      QStringList getStringListWhenWordWrap(QRect(0,0,100,100), myText, font);

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You're looking for QTextLayout - see https://code.qt.io/cgit/qt/qtbase.git/tree/src/gui/painting/qpainter.cpp#n7200

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • T TomNow99 has marked this topic as solved on

      • Login

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