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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:51:27+00:00 2026-06-04T17:51:27+00:00

Ok, so basically I have a simple table with a QWidget and two buttons

  • 0

Ok, so basically I have a simple table with a QWidget and two buttons as shown below:

QGridLayout *layout = new QGridLayout;
layout->addWidget(viewcontainer,0,0,1,2);
layout->addWidget(reset,1,0);
layout->addWidget(done,1,1);

This is basically what I want, where “reset” and “done” are buttons. Essentially it’s a QWidget, viewcontainer, which resizes as the window size is changed by the user while the buttons’ heights remains the same. But, the default for the gridlayout is to align the contents to the left. If I change this with:

layout->addWidget(viewcontainer,0,0,1,2, Qt::AlignCenter);

It does sort of what I want, but the graphicsscene no longer resizes (remains a small constant size). I’d like to retain the resizing while just aligning the widget to the center. Thanks.

  • 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-04T17:51:30+00:00Added an answer on June 4, 2026 at 5:51 pm

    I think the easiest solution which provides a clean solution is to nest 2 layouts.

    Your ‘outer’ (parent) layout should be a QHBoxLayout and you can add your QGridLayout into it as an ‘inner’ (child) layout with addLayout().

    Based on my experience you should avoid to set Qt::Alignment every time you can. It can really mess up your layout. For simple layouts it can work but for more complex ones you should avoid it. And you never know that you should extend your layout in the future or not so my suggestion is to use nested layouts.

    Of course you can create a QWidget for the ‘outer’ layout and for the ‘innser’ layout as well but most of the times it should be fine to just nest 2 layouts.

    Also you can use QSpacerItem to fine-tune your layout.

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

Sidebar

Related Questions

Basically I have two controllers using CodeIgniter for a simple blog for a project
I have a simple application which basically consists of a line of buttons and
Fiddle demo available here: http://jsfiddle.net/r9MCW/5/ The functionality Basically, I have a very simple table
I'm trying to do something relatively simple here. Basically I have a table with
Basically I have some simple code that does some things for files and I'm
I have a pretty simple problem. Basically I have an array called $list that
I have a simple controller called list_controller with an index that basically does def
I have a simple script that does some search and replace. This is basically
I have a really simple Rails app. Basically an article with comments. I want
I'm at my wits end, and it's probably something really simple. Basically I've have

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.