How to adjust the space between the layout using pyqt4





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















Here is my code,i want to reduce the space between the layout.Can any one please tell me how can i reduce the space between the layouts. i tried many ways i used addStrech methos and set content margin also.But i didn't get the proper output.i dont have any idea where i did mistake.please guide me. Thank you in advance.
Given below is my code:



class Example1(QtGui.QWidget):

def __init__(self,typ):
super(Example1, self).__init__()
self.initUI()

def initUI(self):

self.grid2 = QtGui.QGridLayout()
self.vbox1 = QtGui.QVBoxLayout()

self.hbox3 = QtGui.QHBoxLayout()

self.alignvbox = QtGui.QVBoxLayout()

self.label = QtGui.QLabel("Payment Details")
self.label.setStyleSheet("font: bold 30pt Comic Sans MS")
self.hbox3.addWidget(self.label,QtCore.Qt.AlignTop)
self.hbox3.addStretch()
self.label2 = QtGui.QLabel("Amount : ")

self.label2.setStyleSheet("font: bold 15pt Comic Sans MS")
self.label3 = QtGui.QLabel("Quantity : ")
self.label3.setStyleSheet("font: bold 15pt Comic Sans MS")
self.amountvbox = QtGui.QVBoxLayout()
self.amountvbox.setContentsMargins(0, 0, 0, 0)
self.amountvbox.addWidget(self.label2)
self.quantityvbox = QtGui.QVBoxLayout()
self.quantityvbox.setContentsMargins(0, 0, 0, 0)
self.quantityvbox.addWidget(self.label3)
self.vbox1.addLayout(self.amountvbox)
self.vbox1.addLayout(self.quantityvbox)

self.hbox3.addLayout(self.vbox1,QtCore.Qt.AlignTop)

self.alignvbox.addLayout(self.hbox3,QtCore.Qt.AlignTop)
self.hbox4 = QtGui.QHBoxLayout()
self.wbtn1 = QtGui.QPushButton("CASH")
self.wbtn1.setStyleSheet(ROUNDED_STYLE_SHEET2)
self.hbox4.addWidget(self.wbtn1)

self.wbtn2 = QtGui.QPushButton("CARD")
self.wbtn2.setStyleSheet(ROUNDED_STYLE_SHEET3)
self.hbox4.addWidget(self.wbtn2)

self.wbtn3 = QtGui.QPushButton("WALLET")
self.wbtn3.setStyleSheet(ROUNDED_STYLE_SHEET4)
self.hbox4.addWidget(self.wbtn3)
self.alignvbox.addLayout(self.hbox4,QtCore.Qt.AlignTop)
self.alignvbox.addStretch()

self.vbox2 = QtGui.QVBoxLayout()

self.label4 = QtGui.QLabel("Received Amount")
self.vbox2.addWidget(self.label4)
self.label4.setStyleSheet("font: bold 30pt Comic Sans MS")
self.lb = QtGui.QLCDNumber()
self.lb.setDigitCount(8)
self.vbox2.addWidget(self.lb)
self.vbox2.setAlignment(QtCore.Qt.AlignTop)
self.hboxlayout = QtGui.QHBoxLayout()

self.hboxlayout.addLayout(self.vbox2)
self.hboxlayout.addStretch()
self.layout = QtGui.QGridLayout()

names = ['7', '8', '9',
'4', '5', '6',
'1', '2', '3',
'<--', '0', '.']

positions = [(i,j) for i in range(4) for j in range(3)]

for position, name in zip(positions, names):
button = QtGui.QPushButton(name)
self.layout.addWidget(button, *position)
self.hboxlayout.addLayout(self.layout)
self.alignvbox.addLayout(self.hboxlayout)
self.setLayout(self.alignvbox)
def main():
app = QtGui.QApplication(sys.argv)
ex = Example1()
ex.show()
ex.setGeometry(300,300,500,500)
sys.exit(app.exec_())









share|improve this question

























  • What spaces do you mean? maybe an image will help

    – eyllanesc
    Jan 3 at 9:49











  • vertical box alignment sir

    – gowthami
    Jan 3 at 9:57











  • Why did you remove the image?

    – eyllanesc
    Jan 3 at 10:01











  • yes sir i want to do same as in your link only

    – gowthami
    Jan 3 at 10:01




















0















Here is my code,i want to reduce the space between the layout.Can any one please tell me how can i reduce the space between the layouts. i tried many ways i used addStrech methos and set content margin also.But i didn't get the proper output.i dont have any idea where i did mistake.please guide me. Thank you in advance.
Given below is my code:



class Example1(QtGui.QWidget):

def __init__(self,typ):
super(Example1, self).__init__()
self.initUI()

def initUI(self):

self.grid2 = QtGui.QGridLayout()
self.vbox1 = QtGui.QVBoxLayout()

self.hbox3 = QtGui.QHBoxLayout()

self.alignvbox = QtGui.QVBoxLayout()

self.label = QtGui.QLabel("Payment Details")
self.label.setStyleSheet("font: bold 30pt Comic Sans MS")
self.hbox3.addWidget(self.label,QtCore.Qt.AlignTop)
self.hbox3.addStretch()
self.label2 = QtGui.QLabel("Amount : ")

self.label2.setStyleSheet("font: bold 15pt Comic Sans MS")
self.label3 = QtGui.QLabel("Quantity : ")
self.label3.setStyleSheet("font: bold 15pt Comic Sans MS")
self.amountvbox = QtGui.QVBoxLayout()
self.amountvbox.setContentsMargins(0, 0, 0, 0)
self.amountvbox.addWidget(self.label2)
self.quantityvbox = QtGui.QVBoxLayout()
self.quantityvbox.setContentsMargins(0, 0, 0, 0)
self.quantityvbox.addWidget(self.label3)
self.vbox1.addLayout(self.amountvbox)
self.vbox1.addLayout(self.quantityvbox)

self.hbox3.addLayout(self.vbox1,QtCore.Qt.AlignTop)

self.alignvbox.addLayout(self.hbox3,QtCore.Qt.AlignTop)
self.hbox4 = QtGui.QHBoxLayout()
self.wbtn1 = QtGui.QPushButton("CASH")
self.wbtn1.setStyleSheet(ROUNDED_STYLE_SHEET2)
self.hbox4.addWidget(self.wbtn1)

self.wbtn2 = QtGui.QPushButton("CARD")
self.wbtn2.setStyleSheet(ROUNDED_STYLE_SHEET3)
self.hbox4.addWidget(self.wbtn2)

self.wbtn3 = QtGui.QPushButton("WALLET")
self.wbtn3.setStyleSheet(ROUNDED_STYLE_SHEET4)
self.hbox4.addWidget(self.wbtn3)
self.alignvbox.addLayout(self.hbox4,QtCore.Qt.AlignTop)
self.alignvbox.addStretch()

self.vbox2 = QtGui.QVBoxLayout()

self.label4 = QtGui.QLabel("Received Amount")
self.vbox2.addWidget(self.label4)
self.label4.setStyleSheet("font: bold 30pt Comic Sans MS")
self.lb = QtGui.QLCDNumber()
self.lb.setDigitCount(8)
self.vbox2.addWidget(self.lb)
self.vbox2.setAlignment(QtCore.Qt.AlignTop)
self.hboxlayout = QtGui.QHBoxLayout()

self.hboxlayout.addLayout(self.vbox2)
self.hboxlayout.addStretch()
self.layout = QtGui.QGridLayout()

names = ['7', '8', '9',
'4', '5', '6',
'1', '2', '3',
'<--', '0', '.']

positions = [(i,j) for i in range(4) for j in range(3)]

for position, name in zip(positions, names):
button = QtGui.QPushButton(name)
self.layout.addWidget(button, *position)
self.hboxlayout.addLayout(self.layout)
self.alignvbox.addLayout(self.hboxlayout)
self.setLayout(self.alignvbox)
def main():
app = QtGui.QApplication(sys.argv)
ex = Example1()
ex.show()
ex.setGeometry(300,300,500,500)
sys.exit(app.exec_())









share|improve this question

























  • What spaces do you mean? maybe an image will help

    – eyllanesc
    Jan 3 at 9:49











  • vertical box alignment sir

    – gowthami
    Jan 3 at 9:57











  • Why did you remove the image?

    – eyllanesc
    Jan 3 at 10:01











  • yes sir i want to do same as in your link only

    – gowthami
    Jan 3 at 10:01
















0












0








0








Here is my code,i want to reduce the space between the layout.Can any one please tell me how can i reduce the space between the layouts. i tried many ways i used addStrech methos and set content margin also.But i didn't get the proper output.i dont have any idea where i did mistake.please guide me. Thank you in advance.
Given below is my code:



class Example1(QtGui.QWidget):

def __init__(self,typ):
super(Example1, self).__init__()
self.initUI()

def initUI(self):

self.grid2 = QtGui.QGridLayout()
self.vbox1 = QtGui.QVBoxLayout()

self.hbox3 = QtGui.QHBoxLayout()

self.alignvbox = QtGui.QVBoxLayout()

self.label = QtGui.QLabel("Payment Details")
self.label.setStyleSheet("font: bold 30pt Comic Sans MS")
self.hbox3.addWidget(self.label,QtCore.Qt.AlignTop)
self.hbox3.addStretch()
self.label2 = QtGui.QLabel("Amount : ")

self.label2.setStyleSheet("font: bold 15pt Comic Sans MS")
self.label3 = QtGui.QLabel("Quantity : ")
self.label3.setStyleSheet("font: bold 15pt Comic Sans MS")
self.amountvbox = QtGui.QVBoxLayout()
self.amountvbox.setContentsMargins(0, 0, 0, 0)
self.amountvbox.addWidget(self.label2)
self.quantityvbox = QtGui.QVBoxLayout()
self.quantityvbox.setContentsMargins(0, 0, 0, 0)
self.quantityvbox.addWidget(self.label3)
self.vbox1.addLayout(self.amountvbox)
self.vbox1.addLayout(self.quantityvbox)

self.hbox3.addLayout(self.vbox1,QtCore.Qt.AlignTop)

self.alignvbox.addLayout(self.hbox3,QtCore.Qt.AlignTop)
self.hbox4 = QtGui.QHBoxLayout()
self.wbtn1 = QtGui.QPushButton("CASH")
self.wbtn1.setStyleSheet(ROUNDED_STYLE_SHEET2)
self.hbox4.addWidget(self.wbtn1)

self.wbtn2 = QtGui.QPushButton("CARD")
self.wbtn2.setStyleSheet(ROUNDED_STYLE_SHEET3)
self.hbox4.addWidget(self.wbtn2)

self.wbtn3 = QtGui.QPushButton("WALLET")
self.wbtn3.setStyleSheet(ROUNDED_STYLE_SHEET4)
self.hbox4.addWidget(self.wbtn3)
self.alignvbox.addLayout(self.hbox4,QtCore.Qt.AlignTop)
self.alignvbox.addStretch()

self.vbox2 = QtGui.QVBoxLayout()

self.label4 = QtGui.QLabel("Received Amount")
self.vbox2.addWidget(self.label4)
self.label4.setStyleSheet("font: bold 30pt Comic Sans MS")
self.lb = QtGui.QLCDNumber()
self.lb.setDigitCount(8)
self.vbox2.addWidget(self.lb)
self.vbox2.setAlignment(QtCore.Qt.AlignTop)
self.hboxlayout = QtGui.QHBoxLayout()

self.hboxlayout.addLayout(self.vbox2)
self.hboxlayout.addStretch()
self.layout = QtGui.QGridLayout()

names = ['7', '8', '9',
'4', '5', '6',
'1', '2', '3',
'<--', '0', '.']

positions = [(i,j) for i in range(4) for j in range(3)]

for position, name in zip(positions, names):
button = QtGui.QPushButton(name)
self.layout.addWidget(button, *position)
self.hboxlayout.addLayout(self.layout)
self.alignvbox.addLayout(self.hboxlayout)
self.setLayout(self.alignvbox)
def main():
app = QtGui.QApplication(sys.argv)
ex = Example1()
ex.show()
ex.setGeometry(300,300,500,500)
sys.exit(app.exec_())









share|improve this question
















Here is my code,i want to reduce the space between the layout.Can any one please tell me how can i reduce the space between the layouts. i tried many ways i used addStrech methos and set content margin also.But i didn't get the proper output.i dont have any idea where i did mistake.please guide me. Thank you in advance.
Given below is my code:



class Example1(QtGui.QWidget):

def __init__(self,typ):
super(Example1, self).__init__()
self.initUI()

def initUI(self):

self.grid2 = QtGui.QGridLayout()
self.vbox1 = QtGui.QVBoxLayout()

self.hbox3 = QtGui.QHBoxLayout()

self.alignvbox = QtGui.QVBoxLayout()

self.label = QtGui.QLabel("Payment Details")
self.label.setStyleSheet("font: bold 30pt Comic Sans MS")
self.hbox3.addWidget(self.label,QtCore.Qt.AlignTop)
self.hbox3.addStretch()
self.label2 = QtGui.QLabel("Amount : ")

self.label2.setStyleSheet("font: bold 15pt Comic Sans MS")
self.label3 = QtGui.QLabel("Quantity : ")
self.label3.setStyleSheet("font: bold 15pt Comic Sans MS")
self.amountvbox = QtGui.QVBoxLayout()
self.amountvbox.setContentsMargins(0, 0, 0, 0)
self.amountvbox.addWidget(self.label2)
self.quantityvbox = QtGui.QVBoxLayout()
self.quantityvbox.setContentsMargins(0, 0, 0, 0)
self.quantityvbox.addWidget(self.label3)
self.vbox1.addLayout(self.amountvbox)
self.vbox1.addLayout(self.quantityvbox)

self.hbox3.addLayout(self.vbox1,QtCore.Qt.AlignTop)

self.alignvbox.addLayout(self.hbox3,QtCore.Qt.AlignTop)
self.hbox4 = QtGui.QHBoxLayout()
self.wbtn1 = QtGui.QPushButton("CASH")
self.wbtn1.setStyleSheet(ROUNDED_STYLE_SHEET2)
self.hbox4.addWidget(self.wbtn1)

self.wbtn2 = QtGui.QPushButton("CARD")
self.wbtn2.setStyleSheet(ROUNDED_STYLE_SHEET3)
self.hbox4.addWidget(self.wbtn2)

self.wbtn3 = QtGui.QPushButton("WALLET")
self.wbtn3.setStyleSheet(ROUNDED_STYLE_SHEET4)
self.hbox4.addWidget(self.wbtn3)
self.alignvbox.addLayout(self.hbox4,QtCore.Qt.AlignTop)
self.alignvbox.addStretch()

self.vbox2 = QtGui.QVBoxLayout()

self.label4 = QtGui.QLabel("Received Amount")
self.vbox2.addWidget(self.label4)
self.label4.setStyleSheet("font: bold 30pt Comic Sans MS")
self.lb = QtGui.QLCDNumber()
self.lb.setDigitCount(8)
self.vbox2.addWidget(self.lb)
self.vbox2.setAlignment(QtCore.Qt.AlignTop)
self.hboxlayout = QtGui.QHBoxLayout()

self.hboxlayout.addLayout(self.vbox2)
self.hboxlayout.addStretch()
self.layout = QtGui.QGridLayout()

names = ['7', '8', '9',
'4', '5', '6',
'1', '2', '3',
'<--', '0', '.']

positions = [(i,j) for i in range(4) for j in range(3)]

for position, name in zip(positions, names):
button = QtGui.QPushButton(name)
self.layout.addWidget(button, *position)
self.hboxlayout.addLayout(self.layout)
self.alignvbox.addLayout(self.hboxlayout)
self.setLayout(self.alignvbox)
def main():
app = QtGui.QApplication(sys.argv)
ex = Example1()
ex.show()
ex.setGeometry(300,300,500,500)
sys.exit(app.exec_())






python-2.7 pyqt4






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 11:33







gowthami

















asked Jan 3 at 9:43









gowthamigowthami

898




898













  • What spaces do you mean? maybe an image will help

    – eyllanesc
    Jan 3 at 9:49











  • vertical box alignment sir

    – gowthami
    Jan 3 at 9:57











  • Why did you remove the image?

    – eyllanesc
    Jan 3 at 10:01











  • yes sir i want to do same as in your link only

    – gowthami
    Jan 3 at 10:01





















  • What spaces do you mean? maybe an image will help

    – eyllanesc
    Jan 3 at 9:49











  • vertical box alignment sir

    – gowthami
    Jan 3 at 9:57











  • Why did you remove the image?

    – eyllanesc
    Jan 3 at 10:01











  • yes sir i want to do same as in your link only

    – gowthami
    Jan 3 at 10:01



















What spaces do you mean? maybe an image will help

– eyllanesc
Jan 3 at 9:49





What spaces do you mean? maybe an image will help

– eyllanesc
Jan 3 at 9:49













vertical box alignment sir

– gowthami
Jan 3 at 9:57





vertical box alignment sir

– gowthami
Jan 3 at 9:57













Why did you remove the image?

– eyllanesc
Jan 3 at 10:01





Why did you remove the image?

– eyllanesc
Jan 3 at 10:01













yes sir i want to do same as in your link only

– gowthami
Jan 3 at 10:01







yes sir i want to do same as in your link only

– gowthami
Jan 3 at 10:01














1 Answer
1






active

oldest

votes


















1














One possible solution is to set the sizeHint as a fixed size after setting the layouts.



import sys
from PyQt4 import QtCore, QtGui

QSS = '''
QLabel#big{
font: bold 30pt Comic Sans MS
}
QLabel#small{
font: bold 15pt Comic Sans MS
}
'''

class Example1(QtGui.QWidget):
def __init__(self, parent=None):
super(Example1, self).__init__(parent)
self.initUI()

def initUI(self):
grid = QtGui.QGridLayout(self)
label_payment = QtGui.QLabel("Payment Details", objectName="big")
label_received = QtGui.QLabel("Received Amount", objectName="big")

label_amount = QtGui.QLabel("Amount: 192", objectName="small")
label_quantity = QtGui.QLabel("Quantity: 1", objectName="small")

cash_button = QtGui.QPushButton("Cash")
card_button = QtGui.QPushButton("Card")
wallet_button = QtGui.QPushButton("Wallet")

lcd = QtGui.QLCDNumber()
sp = lcd.sizePolicy()
sp.setHorizontalPolicy(QtGui.QSizePolicy.Fixed)
lcd.setSizePolicy(sp)

grid_buttons = QtGui.QGridLayout()

names = ['7', '8', '9',
'4', '5', '6',
'1', '2', '3',
'<--', '0', '.']
positions = [(i,j) for i in range(4) for j in range(3)]
for position, name in zip(positions, names):
button = QtGui.QPushButton(name)
grid_buttons.addWidget(button, *position)

grid.addWidget(label_payment, 0, 0, 2, 3)
grid.addWidget(label_amount, 0, 5)
grid.addWidget(label_quantity, 1, 5)

hbox = QtGui.QHBoxLayout(spacing=0)
hbox.setContentsMargins(0, 0, 0, 0)
hbox.addWidget(cash_button)
hbox.addWidget(card_button)
hbox.addWidget(wallet_button)
grid.addLayout(hbox, 3, 0, 1, 6)

vbox = QtGui.QVBoxLayout(spacing=0)
vbox.setContentsMargins(0, 0, 0, 0)
vbox.addWidget(label_received)
vbox.addWidget(lcd)
grid.addLayout(vbox, 4, 1)

grid.addLayout(grid_buttons, 4, 3, 4, 3)
self.setFixedSize(self.sizeHint())

def main():
app = QtGui.QApplication(sys.argv)
app.setStyleSheet(QSS)
ex = Example1()
ex.show()
ex.setGeometry(300,300,500,500)
sys.exit(app.exec_())

if __name__ == '__main__': main()


enter image description here






share|improve this answer
























  • oh thank you sir

    – gowthami
    Jan 3 at 10:47











  • sir is there any other method to reduce the space between the layout because when i expand the full size of the widget its displays the more space in layout

    – gowthami
    Jan 4 at 4:58












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54019700%2fhow-to-adjust-the-space-between-the-layout-using-pyqt4%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














One possible solution is to set the sizeHint as a fixed size after setting the layouts.



import sys
from PyQt4 import QtCore, QtGui

QSS = '''
QLabel#big{
font: bold 30pt Comic Sans MS
}
QLabel#small{
font: bold 15pt Comic Sans MS
}
'''

class Example1(QtGui.QWidget):
def __init__(self, parent=None):
super(Example1, self).__init__(parent)
self.initUI()

def initUI(self):
grid = QtGui.QGridLayout(self)
label_payment = QtGui.QLabel("Payment Details", objectName="big")
label_received = QtGui.QLabel("Received Amount", objectName="big")

label_amount = QtGui.QLabel("Amount: 192", objectName="small")
label_quantity = QtGui.QLabel("Quantity: 1", objectName="small")

cash_button = QtGui.QPushButton("Cash")
card_button = QtGui.QPushButton("Card")
wallet_button = QtGui.QPushButton("Wallet")

lcd = QtGui.QLCDNumber()
sp = lcd.sizePolicy()
sp.setHorizontalPolicy(QtGui.QSizePolicy.Fixed)
lcd.setSizePolicy(sp)

grid_buttons = QtGui.QGridLayout()

names = ['7', '8', '9',
'4', '5', '6',
'1', '2', '3',
'<--', '0', '.']
positions = [(i,j) for i in range(4) for j in range(3)]
for position, name in zip(positions, names):
button = QtGui.QPushButton(name)
grid_buttons.addWidget(button, *position)

grid.addWidget(label_payment, 0, 0, 2, 3)
grid.addWidget(label_amount, 0, 5)
grid.addWidget(label_quantity, 1, 5)

hbox = QtGui.QHBoxLayout(spacing=0)
hbox.setContentsMargins(0, 0, 0, 0)
hbox.addWidget(cash_button)
hbox.addWidget(card_button)
hbox.addWidget(wallet_button)
grid.addLayout(hbox, 3, 0, 1, 6)

vbox = QtGui.QVBoxLayout(spacing=0)
vbox.setContentsMargins(0, 0, 0, 0)
vbox.addWidget(label_received)
vbox.addWidget(lcd)
grid.addLayout(vbox, 4, 1)

grid.addLayout(grid_buttons, 4, 3, 4, 3)
self.setFixedSize(self.sizeHint())

def main():
app = QtGui.QApplication(sys.argv)
app.setStyleSheet(QSS)
ex = Example1()
ex.show()
ex.setGeometry(300,300,500,500)
sys.exit(app.exec_())

if __name__ == '__main__': main()


enter image description here






share|improve this answer
























  • oh thank you sir

    – gowthami
    Jan 3 at 10:47











  • sir is there any other method to reduce the space between the layout because when i expand the full size of the widget its displays the more space in layout

    – gowthami
    Jan 4 at 4:58
















1














One possible solution is to set the sizeHint as a fixed size after setting the layouts.



import sys
from PyQt4 import QtCore, QtGui

QSS = '''
QLabel#big{
font: bold 30pt Comic Sans MS
}
QLabel#small{
font: bold 15pt Comic Sans MS
}
'''

class Example1(QtGui.QWidget):
def __init__(self, parent=None):
super(Example1, self).__init__(parent)
self.initUI()

def initUI(self):
grid = QtGui.QGridLayout(self)
label_payment = QtGui.QLabel("Payment Details", objectName="big")
label_received = QtGui.QLabel("Received Amount", objectName="big")

label_amount = QtGui.QLabel("Amount: 192", objectName="small")
label_quantity = QtGui.QLabel("Quantity: 1", objectName="small")

cash_button = QtGui.QPushButton("Cash")
card_button = QtGui.QPushButton("Card")
wallet_button = QtGui.QPushButton("Wallet")

lcd = QtGui.QLCDNumber()
sp = lcd.sizePolicy()
sp.setHorizontalPolicy(QtGui.QSizePolicy.Fixed)
lcd.setSizePolicy(sp)

grid_buttons = QtGui.QGridLayout()

names = ['7', '8', '9',
'4', '5', '6',
'1', '2', '3',
'<--', '0', '.']
positions = [(i,j) for i in range(4) for j in range(3)]
for position, name in zip(positions, names):
button = QtGui.QPushButton(name)
grid_buttons.addWidget(button, *position)

grid.addWidget(label_payment, 0, 0, 2, 3)
grid.addWidget(label_amount, 0, 5)
grid.addWidget(label_quantity, 1, 5)

hbox = QtGui.QHBoxLayout(spacing=0)
hbox.setContentsMargins(0, 0, 0, 0)
hbox.addWidget(cash_button)
hbox.addWidget(card_button)
hbox.addWidget(wallet_button)
grid.addLayout(hbox, 3, 0, 1, 6)

vbox = QtGui.QVBoxLayout(spacing=0)
vbox.setContentsMargins(0, 0, 0, 0)
vbox.addWidget(label_received)
vbox.addWidget(lcd)
grid.addLayout(vbox, 4, 1)

grid.addLayout(grid_buttons, 4, 3, 4, 3)
self.setFixedSize(self.sizeHint())

def main():
app = QtGui.QApplication(sys.argv)
app.setStyleSheet(QSS)
ex = Example1()
ex.show()
ex.setGeometry(300,300,500,500)
sys.exit(app.exec_())

if __name__ == '__main__': main()


enter image description here






share|improve this answer
























  • oh thank you sir

    – gowthami
    Jan 3 at 10:47











  • sir is there any other method to reduce the space between the layout because when i expand the full size of the widget its displays the more space in layout

    – gowthami
    Jan 4 at 4:58














1












1








1







One possible solution is to set the sizeHint as a fixed size after setting the layouts.



import sys
from PyQt4 import QtCore, QtGui

QSS = '''
QLabel#big{
font: bold 30pt Comic Sans MS
}
QLabel#small{
font: bold 15pt Comic Sans MS
}
'''

class Example1(QtGui.QWidget):
def __init__(self, parent=None):
super(Example1, self).__init__(parent)
self.initUI()

def initUI(self):
grid = QtGui.QGridLayout(self)
label_payment = QtGui.QLabel("Payment Details", objectName="big")
label_received = QtGui.QLabel("Received Amount", objectName="big")

label_amount = QtGui.QLabel("Amount: 192", objectName="small")
label_quantity = QtGui.QLabel("Quantity: 1", objectName="small")

cash_button = QtGui.QPushButton("Cash")
card_button = QtGui.QPushButton("Card")
wallet_button = QtGui.QPushButton("Wallet")

lcd = QtGui.QLCDNumber()
sp = lcd.sizePolicy()
sp.setHorizontalPolicy(QtGui.QSizePolicy.Fixed)
lcd.setSizePolicy(sp)

grid_buttons = QtGui.QGridLayout()

names = ['7', '8', '9',
'4', '5', '6',
'1', '2', '3',
'<--', '0', '.']
positions = [(i,j) for i in range(4) for j in range(3)]
for position, name in zip(positions, names):
button = QtGui.QPushButton(name)
grid_buttons.addWidget(button, *position)

grid.addWidget(label_payment, 0, 0, 2, 3)
grid.addWidget(label_amount, 0, 5)
grid.addWidget(label_quantity, 1, 5)

hbox = QtGui.QHBoxLayout(spacing=0)
hbox.setContentsMargins(0, 0, 0, 0)
hbox.addWidget(cash_button)
hbox.addWidget(card_button)
hbox.addWidget(wallet_button)
grid.addLayout(hbox, 3, 0, 1, 6)

vbox = QtGui.QVBoxLayout(spacing=0)
vbox.setContentsMargins(0, 0, 0, 0)
vbox.addWidget(label_received)
vbox.addWidget(lcd)
grid.addLayout(vbox, 4, 1)

grid.addLayout(grid_buttons, 4, 3, 4, 3)
self.setFixedSize(self.sizeHint())

def main():
app = QtGui.QApplication(sys.argv)
app.setStyleSheet(QSS)
ex = Example1()
ex.show()
ex.setGeometry(300,300,500,500)
sys.exit(app.exec_())

if __name__ == '__main__': main()


enter image description here






share|improve this answer













One possible solution is to set the sizeHint as a fixed size after setting the layouts.



import sys
from PyQt4 import QtCore, QtGui

QSS = '''
QLabel#big{
font: bold 30pt Comic Sans MS
}
QLabel#small{
font: bold 15pt Comic Sans MS
}
'''

class Example1(QtGui.QWidget):
def __init__(self, parent=None):
super(Example1, self).__init__(parent)
self.initUI()

def initUI(self):
grid = QtGui.QGridLayout(self)
label_payment = QtGui.QLabel("Payment Details", objectName="big")
label_received = QtGui.QLabel("Received Amount", objectName="big")

label_amount = QtGui.QLabel("Amount: 192", objectName="small")
label_quantity = QtGui.QLabel("Quantity: 1", objectName="small")

cash_button = QtGui.QPushButton("Cash")
card_button = QtGui.QPushButton("Card")
wallet_button = QtGui.QPushButton("Wallet")

lcd = QtGui.QLCDNumber()
sp = lcd.sizePolicy()
sp.setHorizontalPolicy(QtGui.QSizePolicy.Fixed)
lcd.setSizePolicy(sp)

grid_buttons = QtGui.QGridLayout()

names = ['7', '8', '9',
'4', '5', '6',
'1', '2', '3',
'<--', '0', '.']
positions = [(i,j) for i in range(4) for j in range(3)]
for position, name in zip(positions, names):
button = QtGui.QPushButton(name)
grid_buttons.addWidget(button, *position)

grid.addWidget(label_payment, 0, 0, 2, 3)
grid.addWidget(label_amount, 0, 5)
grid.addWidget(label_quantity, 1, 5)

hbox = QtGui.QHBoxLayout(spacing=0)
hbox.setContentsMargins(0, 0, 0, 0)
hbox.addWidget(cash_button)
hbox.addWidget(card_button)
hbox.addWidget(wallet_button)
grid.addLayout(hbox, 3, 0, 1, 6)

vbox = QtGui.QVBoxLayout(spacing=0)
vbox.setContentsMargins(0, 0, 0, 0)
vbox.addWidget(label_received)
vbox.addWidget(lcd)
grid.addLayout(vbox, 4, 1)

grid.addLayout(grid_buttons, 4, 3, 4, 3)
self.setFixedSize(self.sizeHint())

def main():
app = QtGui.QApplication(sys.argv)
app.setStyleSheet(QSS)
ex = Example1()
ex.show()
ex.setGeometry(300,300,500,500)
sys.exit(app.exec_())

if __name__ == '__main__': main()


enter image description here







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 3 at 10:29









eyllanesceyllanesc

87.4k103564




87.4k103564













  • oh thank you sir

    – gowthami
    Jan 3 at 10:47











  • sir is there any other method to reduce the space between the layout because when i expand the full size of the widget its displays the more space in layout

    – gowthami
    Jan 4 at 4:58



















  • oh thank you sir

    – gowthami
    Jan 3 at 10:47











  • sir is there any other method to reduce the space between the layout because when i expand the full size of the widget its displays the more space in layout

    – gowthami
    Jan 4 at 4:58

















oh thank you sir

– gowthami
Jan 3 at 10:47





oh thank you sir

– gowthami
Jan 3 at 10:47













sir is there any other method to reduce the space between the layout because when i expand the full size of the widget its displays the more space in layout

– gowthami
Jan 4 at 4:58





sir is there any other method to reduce the space between the layout because when i expand the full size of the widget its displays the more space in layout

– gowthami
Jan 4 at 4:58




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54019700%2fhow-to-adjust-the-space-between-the-layout-using-pyqt4%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith