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. Ascertaining text width [solved]

Ascertaining text width [solved]

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

    Hi,

    I've looked through the documentation, and not found the answer (or maybe missed it) so I'll ask here. Apologies if the answer is in the docs.

    Imagine I have a button, built as an image so it can have complex graphics affects, say. If I want the button to expand horizontally, I can extract the central column and replicate. On this image I have some text. The text can be anything, in any font, font size, etc. The app wants to expand the image to fit the text, but is there a way to find the width of the text, given the text itself can be of any length and any font attributes ? Some method to get the width of the given text string when rendered in the font specified, so that width can then be used to control the button/image width ?

    Thanks

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Do you mean something like "QFontMetrics":http://qt-project.org/doc/qt-4.8/qfontmetrics.html ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kmt11
        wrote on last edited by
        #3

        Perfect ! Couldn't ask for a better response. Many thanks, much appreciated.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You're welcome !

          Don't forget to update the thread's title to solved so other users may know a solution has been found :)

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          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