Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23276

How can I completely remove padding from PYQT6 widgets?

$
0
0

I'm creating a sign-in box for a GUI app. The sign-in box contains three QLabels, two QLineEdits and a QPushButoon. I have all of these widgets inside a QFrame widget with a QVBoxLayout. I want the widgets to be as close ass possible, but I haven't been able to find a way to do that. I've playing around with the following code to try and find a solution. Basically, I want the green, blue and purple labels to be immediately below each other like so:

  • green
  • blue
  • purple
class MainWindow(QMainWindow):    def __init__(self):        super().__init__()        self.setWindowTitle("My App")        layout = QVBoxLayout()        boxLayout = QVBoxLayout()        masterframe = Color('black')        color1 = QLabel('green')        color1.setStyleSheet("""padding: 0px; background-color: green; margin: 0px 0px 0px 0px""")         color2 = QLabel('blue')        color2.setStyleSheet("""padding: 0px; background-color: blue; margin: 0px 0px 0px 0px""")        color3 = QLabel('purple')        color3.setStyleSheet("""padding: 0px; background-color: purple; margin: 0px 0px 0px 0px""")        boxLayout.addWidget(color1)        boxLayout.addWidget(color2)        boxLayout.addWidget(color3)        masterframe.setLayout(boxLayout)        masterframe.setFixedSize(100,500)        layout.addWidget(masterframe)        widget = QWidget()        widget.setLayout(layout)        self.setCentralWidget(widget)app = QApplication(sys.argv)window = MainWindow()window.show()app.exec()

The image below illustrates my problem, I want the padding of each box to be 0 so that the labels can be immediately below each other:

GUI

I've tried using the .move() function but the widgets won't move since the master Frame has a fixed size. I've tried applying CSS style sheets with 0 padding and 0 margin but the widgets still won't align as I want them.


Viewing all articles
Browse latest Browse all 23276

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>