Layout 在布局中重新排序小部件
我有一个senario,我有QComboxes(黑色矩形)和QPushButtons(红色立方体)。我需要这两个按钮始终位于最右边组合的两侧 代码示例:Layout 在布局中重新排序小部件,layout,widget,pyqt,Layout,Widget,Pyqt,我有一个senario,我有QComboxes(黑色矩形)和QPushButtons(红色立方体)。我需要这两个按钮始终位于最右边组合的两侧 代码示例: self.button1 QPushButton() self.button2 = QPushButton() def addCombo(): # remove buttons from next to previous right most combo layout.removeWidget( self.button1
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
如果您有任何想法、提示或解决方案,请告诉我。我认为嵌套布局将对您有所帮助。不要只使用其他按钮将组合框添加到主布局中,而是将组合框添加到它们自己的布局中,然后将该布局添加到主布局中。从内部布局中添加和删除组合框应该会更容易,其他所有内容都保留在原来的位置。我认为嵌套布局将在这方面对您有所帮助。不要只使用其他按钮将组合框添加到主布局中,而是将组合框添加到它们自己的布局中,然后将该布局添加到主布局中。从内部布局中添加和删除组合框应该更容易,其他所有内容都保留在原来的位置