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. How can we know the width and height of string ?
Forum Updated to NodeBB v4.3 + New Features

How can we know the width and height of string ?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 2.0k 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.
  • P Offline
    P Offline
    pratik041
    wrote on last edited by
    #1

    I want to create a button exactly the same size as the string for this i want the width and height of the string.

    Pratik Agrawal

    1 Reply Last reply
    0
    • P Offline
      P Offline
      p-himik
      wrote on last edited by
      #2

      If you use layout than you can just properly specify size constraints. Otherwise you can use "QFontMetrics":http://developer.qt.nokia.com/doc/qt-4.7/qfontmetrics.html

      1 Reply Last reply
      0
      • AlicemirrorA Offline
        AlicemirrorA Offline
        Alicemirror
        wrote on last edited by
        #3

        In QML you can also use the paintedHeight and width properties. Take care of a detail (not sure it is a bug):

        When you use a word-wrapped string you should forcerly add a '\n' character ad the end of the string else the painted properties alway returns the corresponding sized minus the last wrapped line.

        Enrico Miglino (aka Alicemirror)
        Balearic Dynamics
        Islas Baleares, Ibiza (Spain)
        www.balearicdynamics.com

        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