根据您的建议,我找到了解决方案。我稍微修改了 PyQt4/uic/uiparser.py。
361 def createSpacer(self, elem):
362 name = elem.attrib.get('name') #get the name
363 width = elem.findtext("property/size/width")
364 height = elem.findtext("property/size/height")
365
366 if width is None or height is None:
367 size_args = ()
368 else:
369 size_args = (int(width), int(height))
370
371 sizeType = self.wprops.getProperty(elem, "sizeType",
372 QtGui.QSizePolicy.Expanding)
373
374 policy = (QtGui.QSizePolicy.Minimum, sizeType)
375
376 if self.wprops.getProperty(elem, "orientation") == QtCore.Qt.Horizontal:
377 policy = policy[1], policy[0]
378
379 spacer = self.factory.createQObject("QSpacerItem",
380 self.uniqueName(name), size_args + policy,
381 is_attribute=True) #is_attribute=True + set name
382
383 if self.stack.topIsLayout():
384 lay = self.stack.peek()
385 gp = elem.attrib["grid-position"]
386
387 if isinstance(lay, QtGui.QFormLayout):
388 lay.setItem(gp[0], self._form_layout_role(gp), spacer)
389 else:
390 lay.addItem(spacer, *gp)
感谢帮助!