Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
QPainter 上の Qt プログラムで、テキストとその周囲のさまざまな要素を描画します。このテキストが占めるサイズをピクセル単位で取得する必要があります。
テキスト文字列とフォントを知っていれば、どうにかしてサイズをピクセル単位で取得できますか?
ありがとう。
この目的で QFontMetrics を使用できます。以下は Qt Docs のサンプルです。
QFont font("times", 24); QFontMetrics fm(font); int pixelsWide = fm.width("What's the width of this text?"); int pixelsHigh = fm.height();