python - How can I stretch a single widget in a horizantal layout in PyQt4? -
here 3 pushbutton equivalent in size, how increase size of first pushbutton occupies more space other 2 buttons.
from pyqt4 import qtgui import sys class allwidgets(qtgui.qwidget): def __init__(self): super(allwidgets, self).__init__() layout = qtgui.qhboxlayout() #code pushbutton 1 pushbutton_1 = qtgui.qpushbutton() pushbutton_1.settext('first') layout.addwidget(pushbutton_1) #code pushbutton 2 pushbutton_2 = qtgui.qpushbutton() pushbutton_2.settext('second') layout.addwidget(pushbutton_2) #code pushbutton 3 pushbutton_3 = qtgui.qpushbutton() pushbutton_3.settext('third') layout.addwidget(pushbutton_3) self.setlayout(layout) if __name__ == '__main__': app = qtgui.qapplication(sys.argv) display = allwidgets() display.show() sys.exit(app.exec_())
the second (optional) argument of addwigdet()
strech factor. if want first button stretch, do:
layout.addwidget(pushbutton_1, 1)
if want buttons stretch, first 1 bigger, need use different stretch factors:
layout.addwidget(pushbutton_1, 2) layout.addwidget(pushbutton_2, 1) layout.addwidget(pushbutton_3, 1)
Comments
Post a Comment