views:

84

answers:

2

In the following code, I'd like to get rid of the margin around the buttons. I'd like to have the buttons stretch all the way to the edge of the frame. How can I do that?

import sys

from PyQt4.QtGui import *
from PyQt4.QtCore import *

app = QApplication(sys.argv)
window = QWidget()
layout = QVBoxLayout()
layout.setSpacing(0)
window.setLayout(layout)
for i in range(2):
    layout.addWidget(QPushButton())
window.show()
app.exec_()
+3  A: 
layout.setContentsMargin(0, 0, 0, 0)

should do the trick

leinir
It works, thanks. (but it should be Margins, not Margin)
Jesse Aldridge
Ah yes sorry, i was doing it by memory there, and i normally let KDevelop4 do at least part of the typing for me ;)
leinir
+1  A: 

Unfortunately I don't have a working Qt at hand to try right now, but I believe you might get your wish by using style sheets with both margins and padding set to 0 (you might also need to tweak the size policy, as it might otherwise block the widgets from some kind of stretching your style requires).

Alex Martelli