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 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'm trying to create an array from selected table rows so I can push
I have this piece of code. I want to remove the rows created with
Trying to make the infamous checkall checkbox for dynamically created rows from a MySQL
I have two columns in my table and the rows are created dynamically. <table
I have created a listview with 3 rows in Android. If I would like
I have created mysql to delete table rows, which have lower DATETIME value than
Table is created, but rows are empty, why? MySqlConnection conn = new MySqlConnection(...); conn.Open();
I've created a dataset which contains +/- 13000 rows with +/- 50 features. I
I have a table with 100 or more rows that are created at runtime
My sql table is something like (message,created) I want to select those rows which

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.