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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:14:19+00:00 2026-05-18T11:14:19+00:00

Good morning, I have to layout some QWidgets and layouts into a main layout,

  • 0

Good morning,
I have to layout some QWidgets and layouts into a main layout, but I have a problem with a space that I can not remove.
Basically what I would achieve is a horizzontal layout containing a grid layout and some buttons ( all in a horizontal line ). The grid layout (2×2) contains 2 QLabels and 2 QLeds.
Unfortunately Qt place a space between the grid layout and the first button as you can see in the attached image here http://img413.imageshack.us/img413/9132/problemhu.png
I would remove such space.
Here the code I wrote:

QGridLayout* gl = new QGridLayout();
gl->setAlignment(Qt::AlignLeft);
gl->setContentsMargins(0, 0, 0, 0);
gl->addWidget(activeLabel, 0, 0);
gl->addWidget(m_focusLed, 0, 1);
gl->addWidget(encodingLabel, 1, 0);
gl->addWidget(m_encodingLed, 1, 1);

This created the grid layout and added the QLabels and QLeds on it.
Then I add the buttons into the horizontal layout so:

  /* layout buttons */
  QHBoxLayout* lo = new QHBoxLayout();
  lo->setSpacing(0);
  lo->addLayout(gl); // <--here I add the grid layout
  lo->addWidget(m_goToBeginBtn);
  lo->addWidget(m_goToEndBtn);
  lo->addWidget(m_frewBtn);
  lo->addWidget(m_fforBtn);
  lo->addSpacing( 10 );
  lo->addWidget(m_ffrewBtn);
  lo->addWidget(m_ffforBtn);
  lo->addSpacing(10);
  lo->addWidget(m_prevBtn);
  lo->addWidget(m_nextBtn);
  lo->addWidget(m_playBtn);
  lo->addWidget(m_stopBtn);
  lo->addWidget(m_cutBtn);
  lo->addSpacing(10);
  lo->addWidget(m_zoomInBtn);
  lo->addWidget(m_zoomOutBtn);
  lo->addSpacing(10);
  lo->addWidget(m_bgSndCheckBox);
  lo->addWidget( m_showPanelBtn);

I don’t know why Qt place such space between the grid layout and the first button. I would remove it. How can I do? I didn’t get help from the Qt mailing list.

Best Regards

  • 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-18T11:14:20+00:00Added an answer on May 18, 2026 at 11:14 am

    How to fix this largely depends on what behavior you want to see. I’m guessing what you want is for the labels and the Leds to stay exactly where they are, and keep their size.

    What is happening is that the grid layout is resizing with your window, (like your buttons), but the left alignment is keeping the controls stuck to the left, thus the space.

    First, remove the gl->setAlignment(Qt::AlignLeft) line.

    Secondly, you want to make sure you set the sizePolicy properly on both your QLabels and your QLeds, because otherwise your QLeds will start to resize horizontally. What you want is a fixed horizontal size policy. Here is an example:

    QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
    sizePolicy.setHeightForWidth(label->sizePolicy().hasHeightForWidth());
    label->setSizePolicy(sizePolicy);
    

    A completely different way to accomplish the same thing would be to add a bunch of calls to setStretch() on your horizontal layout. But you would have to do this for each column in your layout that you want to stretch. Basically each for each button, but skipping the grid layout in the first column. Like this…

    lo->setStretch(1, 1);  // Column 1 is your first button
    lo->setStretch(2, 1);
    ...
    lo->setStretch(19, 1)l  // 19 columns in total, 15 buttons plus 4 spacing.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good Morning, I have a really simple script that works fine on everything but
Good morning, I have an application that run well on iPhone but crash to
Good morning gang. I have a jQuery Datepicker object that is prepoulated using a
Good Morning, i have some Trouble with the Zend Framework and Zend_DB_Select, i want
Good Morning, I have created an ASP.NET 3.5 webform that allows users to search
Good morning. I've been having this issue for some days and have been lokking
Good morning all, I'm sure this is a gimme, but I have no idea
Good morning, I have problem with using MasterPage and jQuery. I using jQuery UI
Good Morning All, I have loaded over 1,300 blurbs into my client's database with
Good Morning, Say I have an insert statement: Insert INTO tblTest (fieldOne,FieldTwo,fieldThree) VALUES ('valueOne','valueTwo','null')

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.