<h3 dir="auto">Bug report</h3>
<p dir="auto"><strong>Bug summary</strong></p>
<p dir="auto">On macOS with PyQt4, when placing a <code class="notranslate">FigureCanvasQTAgg</code> and a <code class="notranslate">QGraphicsView</code> in the same widget, some QWidget recursive repaint and Core Graphics errors (see below) occur when showing the widget.</p>

<p dir="auto"><strong>Code for reproduction</strong></p>

<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from PyQt4 import Qt
import matplotlib

matplotlib.use('Qt4Agg')

from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg
from matplotlib.figure import Figure

app = Qt.QApplication([])

fig = Figure()
ax = fig.add_subplot(111)
ax.plot([0, 1])
canvas = FigureCanvasQTAgg(fig)

scene = Qt.QGraphicsScene()
scene.addRect(0, 0, 10, 10)
view = Qt.QGraphicsView(scene)

layout = Qt.QHBoxLayout()
layout.addWidget(canvas)
layout.addWidget(view)

widget = Qt.QWidget()
widget.setLayout(layout)
widget.show()

app.exec_()"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-v">PyQt4</span> <span class="pl-k">import</span> <span class="pl-v">Qt</span>
<span class="pl-k">import</span> <span class="pl-s1">matplotlib</span>

<span class="pl-s1">matplotlib</span>.<span class="pl-en">use</span>(<span class="pl-s">'Qt4Agg'</span>)

<span class="pl-k">from</span> <span class="pl-s1">matplotlib</span>.<span class="pl-s1">backends</span>.<span class="pl-s1">backend_qt4agg</span> <span class="pl-k">import</span> <span class="pl-v">FigureCanvasQTAgg</span>
<span class="pl-k">from</span> <span class="pl-s1">matplotlib</span>.<span class="pl-s1">figure</span> <span class="pl-k">import</span> <span class="pl-v">Figure</span>

<span class="pl-s1">app</span> <span class="pl-c1">=</span> <span class="pl-v">Qt</span>.<span class="pl-v">QApplication</span>([])

<span class="pl-s1">fig</span> <span class="pl-c1">=</span> <span class="pl-v">Figure</span>()
<span class="pl-s1">ax</span> <span class="pl-c1">=</span> <span class="pl-s1">fig</span>.<span class="pl-en">add_subplot</span>(<span class="pl-c1">111</span>)
<span class="pl-s1">ax</span>.<span class="pl-en">plot</span>([<span class="pl-c1">0</span>, <span class="pl-c1">1</span>])
<span class="pl-s1">canvas</span> <span class="pl-c1">=</span> <span class="pl-v">FigureCanvasQTAgg</span>(<span class="pl-s1">fig</span>)

<span class="pl-s1">scene</span> <span class="pl-c1">=</span> <span class="pl-v">Qt</span>.<span class="pl-v">QGraphicsScene</span>()
<span class="pl-s1">scene</span>.<span class="pl-en">addRect</span>(<span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">10</span>, <span class="pl-c1">10</span>)
<span class="pl-s1">view</span> <span class="pl-c1">=</span> <span class="pl-v">Qt</span>.<span class="pl-v">QGraphicsView</span>(<span class="pl-s1">scene</span>)

<span class="pl-s1">layout</span> <span class="pl-c1">=</span> <span class="pl-v">Qt</span>.<span class="pl-v">QHBoxLayout</span>()
<span class="pl-s1">layout</span>.<span class="pl-en">addWidget</span>(<span class="pl-s1">canvas</span>)
<span class="pl-s1">layout</span>.<span class="pl-en">addWidget</span>(<span class="pl-s1">view</span>)

<span class="pl-s1">widget</span> <span class="pl-c1">=</span> <span class="pl-v">Qt</span>.<span class="pl-v">QWidget</span>()
<span class="pl-s1">widget</span>.<span class="pl-en">setLayout</span>(<span class="pl-s1">layout</span>)
<span class="pl-s1">widget</span>.<span class="pl-en">show</span>()

<span class="pl-s1">app</span>.<span class="pl-en">exec_</span>()</pre></div>
<p dir="auto"><strong>Actual outcome</strong></p>
<p dir="auto">The widgets show correctly, but the following errors are displayed in the console:</p>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="QWidget::repaint: Recursive repaint detected
QWidget::repaint: Recursive repaint detected
Oct  2 14:23:47  python[52865] &lt;Error&gt;: CGContextGetCTM: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
Oct  2 14:23:47  python[52865] &lt;Error&gt;: CGContextConcatCTM: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
[...]"><pre class="notranslate"><code class="notranslate">QWidget::repaint: Recursive repaint detected
QWidget::repaint: Recursive repaint detected
Oct  2 14:23:47  python[52865] &lt;Error&gt;: CGContextGetCTM: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
Oct  2 14:23:47  python[52865] &lt;Error&gt;: CGContextConcatCTM: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
[...]
</code></pre></div>
<p dir="auto"><strong>Expected outcome</strong></p>
<p dir="auto">This does not occur with PyQt5 (tested with 5.9).<br>
This does not occur with matplotlib 2.0.2 and PyQt4.</p>
<p dir="auto">Also, commenting the call to <code class="notranslate">processEvents</code> in <code class="notranslate">FigureCanvasQTAggBase .paintEvent</code>  solves the issue: </p><div class="Box Box--condensed my-2">
  <div class="Box-header f6">
    <p class="mb-0 text-bold">
      <a href="https://github.com/matplotlib/matplotlib/blob/793635c9e745ea91907e1e24806e28994c6a07d0/lib/matplotlib/backends/backend_qt5agg.py#L75">matplotlib/lib/matplotlib/backends/backend_qt5agg.py</a>
    </p>
    <p class="mb-0 color-fg-muted">
         Line 75
      in
      <a data-pjax="true" class="commit-tease-sha" href="/matplotlib/matplotlib/commit/793635c9e745ea91907e1e24806e28994c6a07d0">793635c</a>
    </p>
  </div>
  <div itemprop="text" class="Box-body p-0 blob-wrapper blob-wrapper-embedded data">
    <table class="highlight tab-size mb-0 js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">

        <tbody><tr class="border-0">
          <td id="L75" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="75"></td>
          <td id="LC75" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-v">QtWidgets</span>.<span class="pl-v">QApplication</span>.<span class="pl-en">instance</span>().<span class="pl-en">processEvents</span>() </td>
        </tr>
    </tbody></table>
  </div>
</div>
<p></p>


<p dir="auto"><strong>Matplotlib version</strong></p>

<ul dir="auto">
<li>Operating System: macOS Sierra 10.12.5</li>
<li>Matplotlib Version: 2.1.0rc1</li>
<li>Python Version: Tested with 2.7 (both system and macPorts) and 3.6 (macPorts)</li>
<li>Jupyter Version (if applicable):</li>
<li>Other Libraries: PyQt4 4.12.1</li>
</ul>
<h3 dir="auto">Bug report</h3>
<p dir="auto"><strong>Bug summary</strong></p>
<p dir="auto">As of master,</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ python examples/images_contours_and_fields/plot_streamplot.py
QWidget::repaint: Recursive repaint detected
Fatal Python error: Segmentation fault"><pre class="notranslate"><code class="notranslate">$ python examples/images_contours_and_fields/plot_streamplot.py
QWidget::repaint: Recursive repaint detected
Fatal Python error: Segmentation fault
</code></pre></div>
<p dir="auto">(Qt5Agg backend)</p>
<p dir="auto"><strong>Code for reproduction</strong></p>
<p dir="auto">See above.</p>
<p dir="auto"><strong>Actual outcome</strong></p>
<p dir="auto">NA</p>
<p dir="auto"><strong>Expected outcome</strong></p>
<p dir="auto">Don't crash.</p>
<p dir="auto"><strong>Matplotlib version</strong></p>

<ul dir="auto">
<li>Operating System: Arch Linux</li>
<li>Matplotlib Version: master</li>
<li>Python Version: 3.6</li>
<li>Jupyter Version (if applicable):</li>
<li>Other Libraries: Qt5.9 from pypi in a venv.  <em>does not occur with Arch repo PyQt5</em> (recursive repaint message occurs sometimes, but does not crash even then)</li>
</ul>
<p dir="auto">bisects back to <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/matplotlib/matplotlib/commit/d0eeddb92a8097e11a8711c4997970520bf0bf9a/hovercard" href="https://github.com/matplotlib/matplotlib/commit/d0eeddb92a8097e11a8711c4997970520bf0bf9a"><tt>d0eeddb</tt></a> which is the merge commit for <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="253118156" data-permission-text="Title is private" data-url="https://github.com/matplotlib/matplotlib/issues/9103" data-hovercard-type="pull_request" data-hovercard-url="/matplotlib/matplotlib/pull/9103/hovercard" href="https://github.com/matplotlib/matplotlib/pull/9103">#9103</a>; however, interestingly, the tip of that commit does <em>not</em> crash so something went wrong during the merge.</p>