组框内的组小部件

group widgets inside groupbox

我有一个如下所示的组框:

这是创建它的代码:

def create_settings_group(self):
   group_box_settings = QtGui.QGroupBox(self)
   group_box_settings.setTitle("Settings")

   grid = QtGui.QGridLayout()

   grid.addWidget(self.label_1, 3, 0)
   grid.addWidget(self.label_2, 3, 2)
   grid.addWidget(self.label_3, 0, 0)
   grid.addWidget(self.label_4, 1, 0)
   grid.addWidget(self.label_6, 2, 0)
   grid.addWidget(self.label_7, 3, 4)
   grid.addWidget(self.label_8, 3, 6)
   grid.addWidget(self.label_9, 3, 8)

   grid.addWidget(self.line_edit_1, 0, 1, 1, 9)
   grid.addWidget(self.combo_box_1, 1, 1, 1, 8)
   grid.addWidget(self.push_button_1, 1, 9)
   grid.addWidget(self.combo_box_2, 2, 1, 1, 8)
   grid.addWidget(self.push_button_2, 2, 9)
   grid.addWidget(self.line_edit_2, 3, 1)
   grid.addWidget(self.line_edit_3, 3, 3)
   grid.addWidget(self.line_edit_4, 3, 5)
   grid.addWidget(self.line_edit_5, 3, 7)
   grid.addWidget(self.line_edit_6, 3, 9)

   grid.addWidget(self.check_box_1, 0, 10)
   grid.addWidget(self.check_box_2, 1, 10)
   grid.addWidget(self.check_box_3, 2, 10)

   group_box_settings.setLayout(grid)

   return group_box_settings

正如您所见,加号按钮靠近组合框但远离复选框。我如何将组合框和按钮组合在一起,以便它们跨越它们下面的所有行编辑和标签?

基本上我想实现这样的目标:

解决方案是将 QHBoxLayout 用于 QComboBoxQPushButton 并更改 QPushButtonQSizePolicy 以便它采用 sizeHint() 最大。

   def create_settings_group(self):
      group_box_settings = QtGui.QGroupBox(self)
      group_box_settings.setTitle("Settings")

      grid = QtGui.QGridLayout()

      grid.addWidget(self.label_1, 3, 0)
      grid.addWidget(self.label_2, 3, 2)
      grid.addWidget(self.label_3, 0, 0)
      grid.addWidget(self.label_4, 1, 0)
      grid.addWidget(self.label_6, 2, 0)
      grid.addWidget(self.label_7, 3, 4)
      grid.addWidget(self.label_8, 3, 6)
      grid.addWidget(self.label_9, 3, 8)

      grid.addWidget(self.line_edit_1, 0, 1, 1, 9)

      self.push_button_1.setSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Fixed)
      hlay1 = QtGui.QHBoxLayout()
      hlay1.addWidget(self.combo_box_1)      
      hlay1.addWidget(self.push_button_1)
      grid.addLayout(hlay1, 1, 1, 1, 9)

      self.push_button_2.setSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Fixed)
      hlay2 = QtGui.QHBoxLayout()
      hlay2.addWidget(self.combo_box_2)
      hlay2.addWidget(self.push_button_2)
      grid.addLayout(hlay2, 2, 1, 1, 9)

      grid.addWidget(self.line_edit_2, 3, 1)
      grid.addWidget(self.line_edit_3, 3, 3)
      grid.addWidget(self.line_edit_4, 3, 5)
      grid.addWidget(self.line_edit_5, 3, 7)
      grid.addWidget(self.line_edit_6, 3, 9)

      grid.addWidget(self.check_box_1, 0, 10)
      grid.addWidget(self.check_box_2, 1, 10)
      grid.addWidget(self.check_box_3, 2, 10)

      group_box_settings.setLayout(grid)

      return group_box_settings