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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:02:11+00:00 2026-05-23T19:02:11+00:00

I’m writing my own class, very similar to a toolbar, which will contain widgets

  • 0

I’m writing my own class, very similar to a toolbar, which will contain widgets under a horizontal box layout object inside of it.

I have a widget class serving as a container
I have a widget class deriving from QPushButton, for custom painting (really showing a loaded image at pos 0,0).

I initialize a layout object:

this->buttonLayout = new QHBoxLayout(this);
this->buttonLayout->setContentsMargins(0, 0, 0, 0);
this->buttonLayout->setSpacing(0);
this->buttonLayout->setObjectName("buttonsLayout");

and then i start initializing widgets and “adding” them onto the layout similar to this:

// once button is created.. add it...
this->buttonLayout->addWidget(button);

In the end, I create a spacer object to make sure all my toolbar buttons are aligned to the left.

QSpacerItem * spacerItem = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding);
this->buttonLayout->addItem(spacerItem);

My button class is defining a “setMinimumSize” in the constructor which is correct under a debugger. It’s also redefining “hintSize” which is called during runtime and the values are correct.

My problem is this. I load 3 “buttons” onto the toolbar. All have variable sizes. if the Spacing on the layout is 0 the first two buttons will be truncated by 9 pixels exactly!, but the third one will be okay. if the layout spacing is -1 the buttons will show nicely with their variable size, but will have a two pixel space between them (I don’t want any space). Lastly, if the layout spacing is “9”, Everything will show up fine.

Why is spacing “0” messing up the button layout causing an overlay? Where did the number “9” come from? why are the first two buttons (e.g. everything but the last button) truncated by exactly 9 pixels when spacing is “0”?

I couldn’t find an answer anywhere.

ADDITIONAL INFO:

I’ve narrowed it down to this:

For every button class, I load up a QImage. The hintSize returns its size, it’s correct under debugger. The returned size matches what photoshop says about the image, and what the properties of the image say about it…

however, on the toolbar, after the layout, it is always given its width “- 9” !!! so the following button to the right is always painted over it, hiding 9 x height pixels of the button to the left.

if i manually add a “+9” to the sizeHint in my button class, it works perfectly.

I can’t understand where the problem comes from. somewhere between the layout and the horizontal spacer, pixels are “stolen” and i don’t know what the heck’s going on here.

has anyone encountered something like that? why do I have to “pre-steal” 9 pixels from each button so that the layout is perfect?

  • 1 1 Answer
  • 1 View
  • 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-23T19:02:11+00:00Added an answer on May 23, 2026 at 7:02 pm

    Solution:

    This appears to be a knows Qt problem under OSX. Note the following bug report: https://bugreports.qt.io/browse/QTBUG-14591

    Resolution:

    by setting the Qt::WA_LayoutUsesWidgetRect attribute for each button.

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

Sidebar

Related Questions

I am writing an app for my school newspaper, which is run completely online
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I am doing a simple coin flipping experiment for class that involves flipping a
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from

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.