Padding of widgets in the QHBox layout



  • Hi, I have some widgets the QHBox layout but i face the following two problems:

    1. The size of the box is greater than the widget size. I am not able to do required padding even after using:
      setmargin(0); or setContentsMargin(0,0,0,0)

    2. when I resize my window, the size of the layout box increases horizontally and I do not understand how to fix the size of the layout item box? I referred here but could not find an answer.

    http://qt-project.org/forums/viewthread/11029

    http://stackoverflow.com/questions/9129324/qt-widget-with-layout-space-what-is-it-how-to-remove


  • Moderators

    1. The title says padding, the post says margins. These are two different things so please be specific. setContentsMargin(0,0,0,0) will remove any margin around the widgets in the layout while setSpacing(0) will remove the space between them. Some widgets have padding inside them (e.g. QGroupBox) and this is controlled by the current style. You can override that for example with stylesheets if you need.
      What widgets do you put in the layout?

    2. If you need a constant size layout put it in a dummy widget and fix that widget size. You can't control dimensions of a layout directly.



  • Thank you for your prompt reply.

    1. I am using a push button as a widget. And I have some icons on the push button.

    2. There is a rectangular outline around the button when added to the layout. How can I make that outline invisible


  • Moderators

    Do you mean the red one in the designer? It's not visible at runtime. It's just there to show you where the layout is at design time.

    Otherwise could you post a picture of what you mean and what the problem is?



  • Hey, I am able to solve botht the problems. THe issue was that the size of the layout item is based on the size of the widget that is added to the layout.

    Once, we limit the size of the widget, the layout behaves exactly how I want.
    Thanks a lot.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.