Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyQt5 Quartz backend fails #516

Closed
corranwebster opened this issue Dec 24, 2020 · 4 comments · Fixed by #679
Closed

PyQt5 Quartz backend fails #516

corranwebster opened this issue Dec 24, 2020 · 4 comments · Fixed by #679

Comments

@corranwebster
Copy link
Contributor

Running Kiva explorer with the command ETS_TOOLKIT=qt4.quartz python kiva_explorer.py on MacOS Catalina, with the PyQt5 toolkit installed with python ci/edmtool.py install --toolkit=pyqt5 from the branch of #515 gives a hard crash:

Traceback (most recent call last):
  File "/Users/cwebster/.edm/envs/enable-test-3.6-pyqt5/lib/python3.6/site-packages/enable/qt4/base_window.py", line 212, in paintEvent
    self.handler.paintEvent(event)
  File "/Users/cwebster/.edm/envs/enable-test-3.6-pyqt5/lib/python3.6/site-packages/enable/qt4/base_window.py", line 64, in paintEvent
    self._enable_window._paint(event)
  File "/Users/cwebster/.edm/envs/enable-test-3.6-pyqt5/lib/python3.6/site-packages/enable/abstract_window.py", line 457, in _paint
    self._gc = self._create_gc(size)
  File "/Users/cwebster/.edm/envs/enable-test-3.6-pyqt5/lib/python3.6/site-packages/enable/qt4/quartz.py", line 86, in _create_gc
    self.dc = get_mac_context(self.control.winId())
ValueError: get_mac_context() requires a pointer to an NSView.
Abort trap: 6
@corranwebster
Copy link
Contributor Author

Replacing the line with

self.dc = get_mac_context(int(self.control.winId()))

stops the segfault with PyQt5, but now things are drawing in the wrong location - relative to the window rather than the widget: I suspect that we need to apply a transformation to get it to render into the correct location.

@jwiggins
Copy link
Member

jwiggins commented Feb 16, 2021

I suspect that we need to apply a transformation to get it to render into the correct location.

Even with your fix and a better location computed via self.control.mapToGlobal(self.control.pos()), this still doesn't work correctly. Most of the time it draws an empty window, but messing with the splitter widget in Kiva Explorer will sometimes redraw in such a way that the graphics context appears. I think we might have to stop using ABCGI.CGContextInABox for PyQt5+

Note that I also played around with QWidget.autoFillBackground and calling flush on the GC and neither had any effect.

@jwiggins
Copy link
Member

I see two options here:

  • Figure out what Qt5 is doing differently and try to adapt the Quartz code to that reality.
  • Stop trying to draw directly into the widget's CGContext and use an offscreen context like many other backends.

@jwiggins
Copy link
Member

jwiggins commented Mar 4, 2021

Discussed this offline with @corranwebster. I will be moving forward with the second option from above: just use offscreen rendering for Qt. Once #645 is merged, this should be trivial to implement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants