Subclassing QValue3DAxisFormatter in PySide
-
When I subclass QValue3DAxisFormatter in my application, the application simply hangs and then exits without an exception or explanation. I have tried removing every and all methods in my subclass (even though they are supposed to be implemented, according to the docs) just to test what the problem is, but it always simply exits without explanation. I have looked everywhere for examples of how to achieve this custom formatter in Python, but the only example I can find in any language is this example: https://code.qt.io/cgit/qt/qtdatavis3d.git/tree/examples/datavisualization/qmlaxisformatter?h=5.15, which is the code from the explanation found at https://doc.qt.io/qt-5/qtdatavisualization-qmlaxisformatter-example.html#custom-axis-formatter . I don't really understand how to translate that to Python code (I'm also not looking to make a calendar-based axis), though I've tried the basic setup as follows:
class AxisFormatter(QtDataVisualization.QtDataVisualization.QValue3DAxisFormatter): def __init__(self): super().__init__() print("init") def createNewInstance(self): print("creating new instance") return AxisFormatter() def populateCopy(self, copy: QtDataVisualization.QtDataVisualization.QValue3DAxisFormatter): print("populating copy") super().populateCopy(copy) def recalculate(self) -> None: print("recalculating")
(The only print statement that will print here is the "init" one, then after ~10 seconds of hanging, the application exits.) Ideally I would like to simply map the axis' (integer) value to an array that I provide as an argument to AxisFormatter, but I can't even get this simple boilerplate working.
-
Hey @elunomas
A couple of things related to your Python code from the C++ example you mentioned:When you encounter something like:
QValue3DAxisFormatter::populateCopy(copy);
that will translate intoQValue3DAxisFormatter.populateCopy(copy)
. Callingsuper()
is only required when accessing inherited methods, like thesuper().__init__()
you have in the constructor.If you would like to have that example translated in https://doc.qt.io/qtforpython/examples/index.html#datavisualization I think it's better if you open an issue on JIRA, as a Suggestion https://bugreports.qt.io/projects/PYSIDE
-
Hey @elunomas
A couple of things related to your Python code from the C++ example you mentioned:When you encounter something like:
QValue3DAxisFormatter::populateCopy(copy);
that will translate intoQValue3DAxisFormatter.populateCopy(copy)
. Callingsuper()
is only required when accessing inherited methods, like thesuper().__init__()
you have in the constructor.If you would like to have that example translated in https://doc.qt.io/qtforpython/examples/index.html#datavisualization I think it's better if you open an issue on JIRA, as a Suggestion https://bugreports.qt.io/projects/PYSIDE
@CristianMaureira Thank you for the clarification and suggestion. I will try to create a JIRA issue suggestion.
-
Hey @elunomas
A couple of things related to your Python code from the C++ example you mentioned:When you encounter something like:
QValue3DAxisFormatter::populateCopy(copy);
that will translate intoQValue3DAxisFormatter.populateCopy(copy)
. Callingsuper()
is only required when accessing inherited methods, like thesuper().__init__()
you have in the constructor.If you would like to have that example translated in https://doc.qt.io/qtforpython/examples/index.html#datavisualization I think it's better if you open an issue on JIRA, as a Suggestion https://bugreports.qt.io/projects/PYSIDE
@CristianMaureira thanks again for the tip. Friedemann Kleint on the Qt JIRA site was able to help by identifying that I need a persistent reference to the formatter -- i.e., self.my_axis = AxisFormatter() instead of just self.chart.axisX().setFormatter(AxisFormatter()). You pointed me in the right direction to get help (and maybe this will be addressed in a future Qt release), so thanks!