Here all three pushbutton are equivalent in size, how to increase size of only first pushbutton so that it occupies more space than other two buttons.
from PyQt4 import QtGui
import sys
class AllWidgets(QtGui.QWidget):
def __init__(self):
super(AllWidgets, self).__init__()
layout = QtGui.QHBoxLayout()
#code for pushbutton 1
pushbutton_1 = QtGui.QPushButton()
pushbutton_1.setText('First')
layout.addWidget(pushbutton_1)
#code for pushbutton 2
pushbutton_2 = QtGui.QPushButton()
pushbutton_2.setText('Second')
layout.addWidget(pushbutton_2)
#code for 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()
is the strech factor. If you want first button to stretch, simply do:
layout.addWidget(pushbutton_1, 1)
If you want all buttons to stretch, but the first one to be bigger, you simply need to use different stretch factors:
layout.addWidget(pushbutton_1, 2)
layout.addWidget(pushbutton_2, 1)
layout.addWidget(pushbutton_3, 1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With