Qt removes white space between widgets on QVBoxLayout

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

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

And then I have a 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 to achieve? Similarly , but without any spaces between widgets added to the layout. Only QButtons or another widget tied to each other.

I have added everywhere setMargins, setSpacing, etc. Please help me with this, I really do not know what to do.

enter image description here

, , . mainWindow, QWidget. . , , . , . - .

+4
4

, , , . , , :

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

- 2 "QtextEdit", , .

enter image description here

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

+1

, "" . : , . , , , ...

// After all widgets are added to the layout
layout->insertStretch( -1, 1 );

. , , , .

+2

?

Qt, - .

QPushButton:

GUI , 3 . Qt , .

, - , . "" , 0.

Soultion

, - stylesheet .


, :

0, :

 QPushButton {
     border: 2px solid #8f8f91;
     border-radius: 6px;
     background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                       stop: 0 #f6f7fa, stop: 1 #dadbde);
     min-width: 80px;
 }

// (further stylesheet for button click is needed)

:

enter image description here

QPushButton, :

enter image description here

, QPushButton . .

+1

, , , - , . , , , . (http://doc.qt.io/qt-5/layout.html: )

It seems that you can implement the Layout class, which actually provides a very compact horizontal or vertical layout, and I believe that I wrote several years ago using Python and Qt. With this in mind, you should be able to implement your own MyCompactLayout(horizontal=True)and use it.

0
source

All Articles