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

  • Home
  • SEARCH
  • 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 6815769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:50:47+00:00 2026-05-26T20:50:47+00:00

I created 2 rows of push buttons, each row is inside a QHBoxLayout. I

  • 0

I created 2 rows of push buttons, each row is inside a QHBoxLayout.
enter image description here

I create the buttons in the code:

static const char* buttonText = "23456789TJQKA";
for (int ii = 0; buttonText[ii]; ii++)
{
    QPushButton* pushButton = new QPushButton(this);
    pushButton->setText(QString(buttonText[ii]));
    ui->horizontalLayout_1->addWidget(pushButton);
}
for (int ii = 0; buttonText[ii]; ii++)
{
    QPushButton* pushButton = new QPushButton(this);
    pushButton->setText(QString(buttonText[ii]));
    ui->horizontalLayout_2->addWidget(pushButton);
}

The problem is that they can’t shrink (when the user resizes the dialog) beyond that size, even though their text would fit in a much smaller width. If I create the buttons manually in the resource editor instead of in the code, they can have smaller width than that.

  • 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-05-26T20:50:47+00:00Added an answer on May 26, 2026 at 8:50 pm

    This happens because the minimumSizeHint of the QPushButton does not allow the QLayout to resize it :

    The default implementation of minimumSizeHint() returns an invalid
    size if there is no layout for this widget, and returns the layout’s
    minimum size otherwise. Most built-in widgets reimplement
    minimumSizeHint().

    QLayout will never resize a widget to a size smaller than the minimum
    size hint unless minimumSize() is set or the size policy is set to
    QSizePolicy::Ignore. If minimumSize() is set, the minimum size hint
    will be ignored.

    The simple solution is to set the minimum width explicitly:

    static const char* buttonText = "23456789TJQKA";
    for (int ii = 0; buttonText[ii]; ii++)
    {
       QPushButton* pushButton = new QPushButton(this);
       pushButton->setMinimumWidth(5);
       pushButton->setText(QString(buttonText[ii]));
       ui->horizontalLayout_1->addWidget(pushButton);
    }
    for (int ii = 0; buttonText[ii]; ii++)
    {
       QPushButton* pushButton = new QPushButton(this);
       pushButton->setMinimumWidth(5);
       pushButton->setText(QString(buttonText[ii]));
       ui->horizontalLayout_2->addWidget(pushButton);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this piece of code. I want to remove the rows created with
I have two columns in my table and the rows are created dynamically. <table
My sql table is something like (message,created) I want to select those rows which
I am trying to create a databound WPF GridView whose rows can either be
I would like to create a query that returns rows in the following format:
I have to create an SQL Query to get all rows starting with a
I'm trying to create a jTable that, once a button is clicked, adds rows
I have a very simple table with two columns, but has 4.5M rows. CREATE
I create tableView with my custom cells. here the code of the cell .h
I'm trying to create a thumbnail gallery with rows of 3 items and I'm

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.