This snippet of code has two labels and two buttons one is ok and one is cancel. when i click ok there appears a new field qLine edit at the top but i wanted to make appear that qlineedit in the center betwen two labels.
'''
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.label_1 = QLabel('Normal Label', self)
self.label_2 = QLabel('second label', self)
self.okButton = QPushButton("OK")
self.okButton.clicked.connect(self.on_click_additional_field)
self.cancelButton = QPushButton("Cancel")
self.hbox = QVBoxLayout()
self.hbox.addStretch(1)
self.hbox.addWidget(self.label_1)
self.hbox.addWidget(self.label_2)
self.hbox.addWidget(self.okButton)
self.hbox.addWidget(self.cancelButton)
self.vbox = QVBoxLayout()
self.vbox.addStretch(1)
self.vbox.addLayout(self.hbox)
self.setLayout(self.vbox)
self.setWindowTitle('Buttons')
self.show()
def on_click_additional_field(self):
self.inspection_dir_path_txt_box = QLineEdit(self)
# self.inspection_dir_path_txt_box.installEventFilter(self)
self.inspection_dir_path_txt_box.move(100, 20)
self.x1 = len(self.vbox)-1
self.vbox.insertWidget(len(self.vbox)-2,self.inspection_dir_path_txt_box)
# self.setGeometry(300, 300, 300, 150)
'''