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. [SOLVED] Scaling QLabel to accommodate the contained text and nothing more
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Scaling QLabel to accommodate the contained text and nothing more

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

    I'm subclassing QLabel and inserting it into a QVBoxLayout and I'm having a problem with the size. The following screenshot is how my application currently looks:

    !http://i.imgur.com/gdBzQ.png(Screenshot)!

    The yellow widget on the top is my QLabel, and the layout is the default one. I'd like my label to scale down to fit the text without manually setting it with setMinimumHeight(), however that wouldn't allow me to use strings longer than the width of the label. I've checked the documentation for QString (which is what I am passing to the label's constructor) and I can't find a way to extract the size of the text. Is there any way I can dynamically change the size of my label to fit the text, with no excess space?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      joonhwan
      wrote on last edited by
      #2

      see following method's documentation

      QRect QFontMetrics::boundingRect ( const QRect & rect, int flags, const QString & text, int tabStops = 0, int * tabArray = 0 ) const

      especially be noted the flags being used for examples

      Qt::TextWordWrap,
      Qt::AlignHCenter and Qt::AlignVCenter(which is Qt::AlignCenter)

      .

      BTW, it looks like kanban board :)

      joonhwan at gmail dot com

      1 Reply Last reply
      0
      • N Offline
        N Offline
        notgary
        wrote on last edited by
        #3

        Thanks a lot for your help. That's exactly what I've been looking for.

        bq. BTW, it looks like kanban board :)

        Well, as it so happens... ;)

        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