我修改了组合框来保存颜色,使用 QtColorCombo ( http://qt.nokia.com/products/appdev/add-on-products/catalog/4/Widgets/qtcolorcombobox ) 作为“更多...”按钮的操作方法实施细节。它在 C++ 和 Linux 上的 PyQt 中运行良好,但在 Windows 上的 PyQt 中使用此控件时,我得到“底层 C++ 对象被破坏”。似乎错误发生在以下情况:
...
# in constructor:
self.activated.connect(self._emitActivatedColor)
...
def _emitActivatedColor(self, index):
if self._colorDialogEnabled and index == self.colorCount():
print '!!!!!!!!! QtGui.QColorDialog.getColor()'
c = QtGui.QColorDialog.getColor() # <----- :( delegate fires 'closeEditor'
print '!!!!!!!!! ' + c.name()
if c.isValid():
self._numUserColors += 1
#at the next line currentColor() tries to access C++ layer and fails
self.addColor(c, self.currentColor().name())
self.setCurrentIndex(index)
...
也许控制台输出会有所帮助。我在编辑器中覆盖了 event() 并得到:
- 鼠标按钮释放
- 焦点输出
- 离开
- 画
- 进入
- 离开
- 专注于
- !!!!!!!!!QtGui.QColorDialog.getColor()
- 窗口阻塞
- 画
- 窗口停用
- !!!!!!!!!“关闭编辑器”开火了!
- 隐藏
- 隐藏到父级
- 聚焦
- 延迟删除
- !!!!!!!!!#6e6eff
有人可以解释一下,为什么在不同的环境中会有如此不同的行为,也许可以提供一种解决方法来解决这个问题。这是最小的例子: http ://docs.google.com/Doc?docid=0Aa0otNVdbWrrZDdxYnF3NV80Y20yam1nZHM&hl=en