Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to make a layout fill the entire window in PyQt5?

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

If I understand you correctely, just add

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

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading