Rami Rosenbaum
Rami Rosenbaum

Reputation: 477

QTextEdit display width vs text width

I'm creating a 'scrolling-text' class in Qt, using a QTextEdit (read-only, no scrollbars, moveCursor) and a QTimer - simple and working.

My problem is when the text sent to the class is shorter (narrower) than the QTextEdit-box. Silly, I agree, but, being new to Qt, I didn't find an easy way to compare the width of the given text (depending on the font) and the actual width that can be displayed inside the QTextEdit (after calculating the FrameStyle, etc.). I presume I need to calculate the pixels.

Any ideas? Thanks

Upvotes: 0

Views: 1222

Answers (1)

leemes
leemes

Reputation: 45725

You can get the width of a text using QFontMetrics:

int textWidth = myTextEdit->fontMetrics().width(myTextEdit->text());

Upvotes: 2

Related Questions