Issue
Using python
, pyside
, I get this error:
self.setCheckState(value)
TypeError: could not convert 'BooleanEditor' to 'QCheckBox'
Beside that many of Google's result only show "TypeError: can not convert" instead of "could", I still have no idea how to fix this.
Code snippet:
class Editor(QGraphicsLayoutItem):
def __init__(self, name):
QGraphicsLayoutItem.__init__(self)
:
:
def update_value(self, value):
pass
class BooleanEditor(Editor, QCheckBox):
def __init__(self, parent, name, value, min, max):
Editor.__init__(self, name)
QCheckBox.__init__(self)
self.update_value(value)
def update_value(self, value):
self.old_value = value
self.setCheckState(value) # Error occurs here.
"value" that setCheckState receives will be Qt.CheckState. Upon running, the "value" is Qt.Unchecked
(== 0) as expected, according to debug printing.
Notice that BooleanEditor
employs multiple inheritance
. I'm porting wxWidget
app (that someone else made) to Qt
, and for now I don't want to change this design because this comes from original (meaning mult inheritance itself here shouldn't be the cause since the original app works fine).
Environment) pyside 1.1.0, python 2.7.3, Ubuntu 12.04
Update-1) As @Luke Woodward suggests, I tried to swap the order of super classes as BooleanEditor(QCheckBox, Editor)
, then get a different error at different part.
class PaneGroup(GroupView, QFrame):
def __init__(self, parent, group, config, top = None):
GroupView.__init__(self, group, top)
QFrame.__init__(self)
:
sizer = QGraphicsGridLayout()
:
for param_descr in self.params:
name = param_descr['name']
type, val, min, max, description = param_descr['type'], config[name], param_descr['min'], param_descr['max'], param_descr['description']
try:
enum = eval(param_descr['edit_method'])['enum']
editor = self.top.EnumEditor(self, name, val, enum)
except:
editor = self.top._editor_types[type](self, name, val, min, max)
self.top.editors[name] = editor
sizer.addItem(editor, row, 1) # Error occurs here
Error:
TypeError: could not convert 'BooleanEditor' to 'QGraphicsLayoutItem'
Looks like an issue about initialization in multiple inheritance to me..
Solution
My very bad, it turned out I was using PyQt4
instead of PySide
. When I use PySide
, error doesn't occur (as @phihag's gist shows) whereas using PyQt4
yields the same result. It's actually curious but I won't investigate further now.
Use the following code for reproduction.
#!/usr/bin/env python
import sys
from PySide.QtCore import Qt
from PySide.QtGui import QApplication, QCheckBox, QGraphicsLayoutItem
#from PyQt4.QtCore import Qt
#from PyQt4.QtGui import QApplication, QCheckBox, QGraphicsLayoutItem
class Editor(QGraphicsLayoutItem):
def __init__(self, name):
QGraphicsLayoutItem.__init__(self)
def update_value(self, value):
pass
class BooleanEditor(Editor, QCheckBox):
def __init__(self, value):
Editor.__init__(self, "foo")
QCheckBox.__init__(self)
self.update_value(value)
def update_value(self, value):
self.old_value = value
self.setCheckState(value) # Error occurs here
print("End of update_value")
if __name__ == "__main__":
qApp = QApplication(sys.argv)
BooleanEditor(Qt.Checked)
PS. Why I didn't know I was using PyQt
? For which one I use, I'm depending on this framework I've been working with (called qt_gui
in ROS
, Robot Operating System), which doesn't explicitly tells me which one in use (it's open source prj and documentation work is ongoing)...After hacking into its codes, I figured out default is PyQt
.
Answered By - IsaacS
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.