Qt remove empty space between widgets on QVBoxLayout

Tatarinho picture Tatarinho · Jan 20, 2015 · Viewed 13k times · Source

I have annoying problem. I created QVBoxLayout on which I added my widgets. This is sample from my constructor:

layout = new QVBoxLayout;
layout->setMargin(0);
layout->setContentsMargins(QMargins(0,0,0,0));
layout->setSpacing(0);

And then I have function to add widgets.

layout->addWidget(_wave);

_wave is my own widget. But you can add whatever you want, for example QButton.

What do I want achieve? Similar like this but without any spaces beetween widgets added to layout. Just only QButtons or other widget, sticked each other.

I added everywhere setMargins, setSpacing etc. Please help me with that, I don't really have an idea what should I do.

enter image description here

Sorry for colors, but I wanted to mentioned what I want to achieve. I have mainWindow on which I added QWidget. This widget have blue background. Then to the layout, Im addding some widgets, which are orange on this image. I just want to be sure, that this blue background between widget isnt visible. I want to have widget under widget, without any space.

Answer

BaldDude picture BaldDude · Jul 29, 2016

I know the question was posted a year ago, but if it can help some people save some time, I would be glad. I had the same problem and was able to solve it by setting:

  • "QFrame.setFrameShape()" to "NoFrame"
  • "QFrame.seLineWidth()" to 0.

The image below is the result of 2 "QtextEdit" put side by side in a Layout, using the described method.

enter image description here

http://doc.qt.io/qt-5/qframe.html#lineWidth-prop