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. Find out labelSize after wordWrap
Forum Updated to NodeBB v4.3 + New Features

Find out labelSize after wordWrap

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 996 Views 1 Watching
  • 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.
  • N Offline
    N Offline
    NeloS
    wrote on last edited by
    #1

    Hi com,

    i have a problem with drawText, wordWrap and QLabel

    I create a QLabel and set a very long text. Then i draw the labelText.

    @
    QLabel *label = new QLabel
    label->setText("a very long text thats not fit in the label width")

    paint->drawText(QRect(10,10,50,16), Qt::alignVCenter | Qt::textWordWrap, label->text());
    @

    How I can find out the new label height after the WordWrap? I Have to set a new height that the text fit in the QRect.

    Greetings Nelo

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      If you call QLabel::setWordWrap(true) and then set the text then the label will adjust itself (within the constraints of its parent and layout).

      If you must paint your widget yourself then use the version of drawText() that takes a pointer to QRectF in which to return the bounding rect of the text.

      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