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 7911859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:24:11+00:00 2026-06-03T13:24:11+00:00

I use a QLabel and QPLineEdit within a QStackedWidget , the QLable should be

  • 0

I use a QLabel and QPLineEdit within a QStackedWidget , the QLable should be nearly the size of the window holding this widget.

But when I set a extra long text to QLabel , it’s expanding too much , and I’m not able to reduce the window size horizontally , the minimum width was too much.

I set the size policy of these three widgets to Minimum already , it just won’t work for me.

UPDATE

maybe it’s better saying like this: how to let QLabel display part of the text , when there’s not enough space

SAMPLE CODE

  #include <QtGui>

int main ( int argc , char **argv ) 
{
    QApplication app (argc , argv);

    QWidget w;
    QLabel *label = new QLabel ("Very very very long text");
    label->setSizePolicy (QSizePolicy::Minimum , QSizePolicy::Fixed);
    QVBoxLayout layout (&w);
    layout.addWidget ( label );
    w.show();
    return  app.exec();
}
  • 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-03T13:24:12+00:00Added an answer on June 3, 2026 at 1:24 pm

    If I understand you correctly, the simplest thing to do is simply to ignore that label’s horizontal size hint.
    As long as you have other widgets in there (or force a minimum width manually to the container), this should do what you want:

    #include <QtGui>
    
    int main(int argc, char **argv)
    {
        QApplication app(argc, argv);
    
        QLabel *l1 = new QLabel("This very long text doesn't influence "
                                "the width of the parent widget");
        l1->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
        // Style just to make it clear that the widget is 
        // being resized to fit the parent, it doesn't "overflow"
        l1->setFrameShape(QFrame::Box);
        l1->setFrameShadow(QFrame::Raised);
        l1->setAlignment(Qt::AlignHCenter);
    
        QLabel *l2 = new QLabel("This influences the width");
        l2->setFrameShape(QFrame::Box);
        l2->setFrameShadow(QFrame::Raised);
    
        QWidget w;
        QVBoxLayout layout(&w);
        layout.addWidget(l1);
        layout.addWidget(l2);
        w.show();
        return app.exec();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The Widget we should use to show pictures is a QLabel. we can do
use this website a lot but first time posting. My program creates a number
I want to use QLabel s to display some data in this format username:.....Erich
Why this code show me a window without image? I try to use QByteArray
I use Qt.4.6 in Nokia phone. My window, derived from QWidget, has set nontiled
use Service layer to persist data into database. But the Unit Test does not
I use a QLabel to display the content of a bigger, dynamically changing QPixmap
This is a question about Qt library, not about Web design. For QLabel and
OS::win_xp_sp3 Qt::4.6 Is it possible to use QMouseEvent inside QRect? I have parent widget
I have a QLabel without any text but with a QPixmap image. I can

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.