Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9062331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:42:41+00:00 2026-06-16T15:42:41+00:00

I have a custom widget which has an overall layout of a QVBoxLayout. It

  • 0

I have a custom widget which has an overall layout of a QVBoxLayout. It contains several labels, a QFormLayout, a button, and a stretch to eat all excess space. One of the labels can be quite large so I am trying to ensure that there are no odd cases where the text is unreadable. The widget is contained within a QScrollArea to ensure that if the user shrinks the overall window all aspects of the widget can still be seen.

The QLabel appears to resize fine, but once it reaches a certain point of narrowness it just cuts off the bottom few lines of the label and allocates the space to the stretch at the bottom of the widget.

I am doing this all in code without the Designer, so it is entirely possible that I am just missing something. The subcomponents are added to the overall QVBoxLayout in the following order:

OverallLayout = new QVBoxLayout(this);
Title         = new QLabel();
Description   = new QLabel();
SubRegion     = new QFormLayout();
Button        = new QButton();
...
// set text values, wordWrap(true), and Font for labels
OverallLayout->addWidget(Title);
OverallLayout->addWidget(Description);
OverallLayout->addLayout(SubRegion);
OverallLayout->addStrut(MIN_DIST);
OverallLayout->addWidget(Button);
OverallLayout->addStretch(STRETCH_FACTOR);

Test results: Examining the results returned from the QLabel’s sizeHint() function, the values returned do not appear to change as the widget is shrunk horizontally. However, the QLabel does expand to take up more vertical room (153 vs the hint of 103), just not enough to fit all of the text. When the QLabel is first shown, it has less pixels than its sizeHint but still enough for its heightForWidth amount. When it is resized, it has 30 less than its heightForWidth amount but more than its sizeHint.

I have checked and the large QLabel has its hasHeightForWidth() and wordWrap() values set to true. What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T15:42:43+00:00Added an answer on June 16, 2026 at 3:42 pm

    I ended up going with the method of overwriting the widget’s resizeEvent(QResizeEvent *evt) function in order to set the maximum value of the QLabel dynamically.

    void MyWidget::resizeEvent (QResizeEvent *evt) {
       int newHeight = Description.heightForWidth(Description.width());
       Description.setMaximumHeight(newHeight);
       QWidget::resizeEvent(evt); 
       // Note: I'm not sure if this last step is necessary
    }
    

    An interesting item to note is that if you do both setMinimumHeight(newHeight) and setMaximumHeight(newHeight) the label will grow vertically to fit the text but it will never shrink when the label grows horizontally and doesn’t need the extra space. My guess is that heightForWidth(int w) returns the max between the widget’s minimumHeight and the pixels actually needed. The odd part is that it doesn’t seem to care about returning a value larger than the current maximumHeight.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a MyWidget which contains a MySubWidget , e.g. a custom widget
lets say i have a custom widget which has a ClickHandler. Here's the example:
I have a custom layout defined in XML file which has a RelativeLayout root
I have a custom ScrollView (extended android.widget.ScrollView) which I use in my layout. I
I have created a custom widget which has a link to some ajax functionality.
I have 2 custom components in Flash Builder, A.mxml which contains B.mxml. B has
I have widget on my Wordpress site which searches my custom taxonomies. The search
I have a custom widget which displays many items in rows: void update(){ //this
I have a custom GTK+ widget which I am compiling in a C++ file
I have a custom Widget derived from QFrame. I will need to draw on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.