Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Subclassing QValue3DAxisFormatter in PySide
Forum Updated to NodeBB v4.3 + New Features

Subclassing QValue3DAxisFormatter in PySide

Scheduled Pinned Locked Moved Solved Qt for Python
4 Posts 2 Posters 382 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    elunomas
    wrote on last edited by elunomas
    #1

    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.

    1 Reply Last reply
    0
    • CristianMaureiraC Offline
      CristianMaureiraC Offline
      CristianMaureira
      wrote on last edited by
      #2

      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 into QValue3DAxisFormatter.populateCopy(copy). Calling super() is only required when accessing inherited methods, like the super().__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

      E 2 Replies Last reply
      1
      • CristianMaureiraC CristianMaureira

        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 into QValue3DAxisFormatter.populateCopy(copy). Calling super() is only required when accessing inherited methods, like the super().__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

        E Offline
        E Offline
        elunomas
        wrote on last edited by
        #3

        @CristianMaureira Thank you for the clarification and suggestion. I will try to create a JIRA issue suggestion.

        1 Reply Last reply
        0
        • CristianMaureiraC CristianMaureira

          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 into QValue3DAxisFormatter.populateCopy(copy). Calling super() is only required when accessing inherited methods, like the super().__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

          E Offline
          E Offline
          elunomas
          wrote on last edited by
          #4

          @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!

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved