here in my sample program i want to add widget to Center of the gridlayout.I used alignments methods but its not working.Can any one please help me how to adjust the my widget in center of the grid layout. Thank you in advance.
Given below is my sample code:
import sys
from PyQt4 import QtGui,QtCore
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
self.grid = QtGui.QGridLayout(self)
self.title_hbox = QtGui.QHBoxLayout()
self.title_hbox.addStretch()
self.close_pushbtn = QtGui.QPushButton("Close")
self.title_hbox.addWidget(self.close_pushbtn)
self.grid.addLayout(self.title_hbox,0,0)
self.line = QtGui.QFrame(frameShape=QtGui.QFrame.HLine)
self.grid.addWidget(self.line,1,0)
self.order_hbox = QtGui.QHBoxLayout()
vbox = QtGui.QVBoxLayout()
label = QtGui.QLabel("address ")
vbox.addWidget(label)
hbox=QtGui.QHBoxLayout()
le =QtGui.QLabel("scroll area")
hbox.addWidget(le)
self.order_hbox.addLayout(vbox)
self.order_hbox.addLayout(hbox)
self.grid.addLayout(self.order_hbox,2,0)
self.addhbox = QtGui.QHBoxLayout()
self.add_btn = QtGui.QPushButton("Add") #@ Add button i want to adjust the center of the gridlayout (its tacking whole length..)
self.addhbox.addWidget(self.add_btn,QtCore.Qt.AlignCenter)
self.grid.addLayout(self.addhbox,3,0)
self.resize(800, 300)
self.show()
def main():
app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
my add button is taking the whole width but i want to adjust the middle of the widget