Issue
i added some widgets to QFormLayout then add this layout to cell in table but it seems the widgets are aligned to top and i want them to be centered vertically so they be in center, here is an image to explain :
the class of making the layout and its widgets:
class Options(QtWidgets.QWidget):
def __init__(self, parent=None,row=[], ops=[]):
super(Options, self).__init__(parent)
self.i = random.randint(1, 100)
self.row = [j.decode("utf-8") if i!=1 else "image" for i,j in enumerate(row)]
self.layout = QFormLayout()
ops = ast.literal_eval(ops[0]) if len(ops[0])>1 else {}
for i,j in ops.items():
#adding widgets here and it is not related!
self.btn = QtWidgets.QPushButton("Submit")
self.btn.clicked.connect(self.do)
self.layout.addWidget(self.btn)
self.setLayout(self.layout)
Solution
Set the vertical alignment of the QFormLayout:
self.layout.setFormAlignment(QtCore.Qt.AlignVCenter)
It's usually better to avoid overwriting existing instance attributes: self.layout()
is a default function for all QWidget descendants; you either use a local variable or a different name.
Answered By - musicamante
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.