April 1, 2011

ronM71 ronM71
Lab Rat
134 posts

DrawText (single line) and Ellipsis

  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

April 1, 2011

ZapB ZapB
Ant Farmer
1454 posts

Take a look at the docs [doc.qt.nokia.com] 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

  ‹‹ QPSQL driver - Postgresql 9 & Windows 7      MAC OSX and zlib issue ››

You must log in to post a reply. Not a member yet? Register here!