Can't remove margins from QVBoxLayout

后端 未结 1 1272
野的像风
野的像风 2021-01-23 04:57

I have set up an image button with some text, but the image does not align with the text due to some extra margins. How can I get rid of these margins? I have tried setting

相关标签:
1条回答
  • 2021-01-23 05:43

    That margin is that of the QVBoxLayout that you use to place the QToolButton inside ImageButton, so the solution is to set it to 0 that margin:

    # ...
    class ImageButton(QWidget):
        def __init__(self, img_location):
            super().__init__(self)
            # ...
            layout = QVBoxLayout(self)
            layout.addWidget(self.button)
            layout.setContentsMargins(0, 0, 0, 0)
        # ...
    0 讨论(0)
提交回复
热议问题