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. DrawText (single line) and Ellipsis
Forum Updated to NodeBB v4.3 + New Features

DrawText (single line) and Ellipsis

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 5.7k 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.
  • R Offline
    R Offline
    ronM71
    wrote on last edited by
    #1

    Qt::TextSingleLine will keep the text in a single line, chopping it off if its dimensions exceed the given rect.

    Is there an automated way to add an ellipsis ("...") to the string and chop it such that the "..." is visible?

    I know I could do it myself with some text dimension measuring that takes the current font and bounding rectangle into consideration. Is there built-in support for this in Qt? I couldn't find any.

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      ZapB
      wrote on last edited by
      #2

      Take a look at the "docs":http://doc.qt.nokia.com/latest/qfontmetrics.html#elidedText for QString QFontMetrics::elidedText ( const QString & text, Qt::TextElideMode mode, int width, int flags = 0 ) const. That should do what you need. You can then paint the resulting string with QPainter as usual.

      Nokia Certified Qt Specialist
      Interested in hearing about Qt related work

      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