1

I have modified combobox to hold colors, using QtColorCombo (http://qt.nokia.com/products/appdev/add-on-products/catalog/4/Widgets/qtcolorcombobox) as howto for the 'more...' button implementation details. It works fine in C++ and in PyQt on linux, but I get 'underlying C++ object was destroyed' when use this control in PyQt on Windows. It seels like the error happens when:

...
# 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)
...

Maybe console output will help. I've overridden event() in editor and got:

  • MouseButtonRelease
  • FocusOut
  • Leave
  • Paint
  • Enter
  • Leave
  • FocusIn
  • !!!!!!!!! QtGui.QColorDialog.getColor()
  • WindowBlocked
  • Paint
  • WindowDeactivate
  • !!!!!!!!! 'CloseEditor' fires!
  • Hide
  • HideToParent
  • FocUsOut
  • DeferredDelete
  • !!!!!!!!! #6e6eff

Can someone explain, why there is such a different behaviour in the different environments, and maybe give a workaround to fix this. Here is the minimal example: http://docs.google.com/Doc?docid=0Aa0otNVdbWrrZDdxYnF3NV80Y20yam1nZHM&hl=en

4

1 に答える 1

1

問題は、QColorDialog.color()がモーダルダイアログを表示し、コンボからフォーカスを取得し、その直後に閉じて、デリゲートがそれを破棄するという事実のようです。したがって、このような問題を解決するための回避策は、イベントの中断です。

代表者の場合:

def eventFilter(self, editor, event):
    if event.type() == QtCore.QEvent.FocusOut and hasattr(editor, 'canFocusOut'):
        if not editor.canFocusOut: return False
    return QtGui.QItemDelegate.eventFilter(self, editor, event)

エディタでは、フラグself.canFocusOutを導入し、FocusOutが禁止されている場合はtrueに設定する必要があります。これは、QColorDialogを示す「highlited」信号が要素で発生したときに実行します。

于 2010-03-18T13:48:51.967 に答える