1

I'm creating an app in PyQt5 and I want a layout that fills the entire window, except the title bar.

When I try to set a QVBoxLayout to a QWidget, there remains a gap, as seen below:

App

This is my code:

def main():
    app = QApplication(sys.argv)
    win = QWidget()

    win.setFixedSize(225,150)

    label = QLabel("Some Label")
    label.setAlignment(QtCore.Qt.AlignCenter)
    label.setStyleSheet('background: red')

    layout = QVBoxLayout()
    layout.addWidget(label)

    win.setLayout(layout)

    win.show()
    sys.exit(app.exec_())

main()

So how do I remove the gap?

Itsjul1an
  • 301
  • 1
  • 2
  • 12

1 Answers1

1

If I understand you correctely, just add

layout.setContentsMargins(0,0,0,0)

anywhere after creating layout object and before sys.exit(app.exec_()).

Andrey
  • 340
  • 2
  • 11