1
我有一個Senario,其中有QComboBoxes(黑色矩形)和QPushButtons(紅色多維數據集)。我需要兩個按鈕始終停留在最右側組合的任一側。在佈局中重新排序小部件
。
代碼示例:
self.button1 QPushButton()
self.button2 = QPushButton()
def addCombo():
# remove buttons from next to previous right most combo
layout.removeWidget(self.button1)
layout.removeWidget(self.button2)
# add button left of new right most combo
layout.addWidget(self.button1)
# add new right most combo
layout.addWidget(QComboBox())
# add button right of new right most combo
layout.addWidget(self.button2)
def removeCombo():
# remove buttons from next to previous right most combo
layout.removeWidget(self.button1)
layout.removeWidget(self.button2)
# delete right most combo
layout.takeAt(len(layout.children()) -1)
# add button left of new right most combo # button , index
layout.insertWidget(self.button1 , len(layout.children()) - 2)
# add button right of new right most combo
layout.addWidget(self.button2)
#So for the first layout:
layout.addWidget(QComboBox())
layout.addWidget(self.button1)
layout.addWidget(QComboBox())
layout.addWidget(self.button2)
#second layout:
addCombo()
#third layout:
addCombo()
# fourth layout
請讓我知道如果您有任何意見,建議或解決方案。
天才!謝謝! – Jared