<br><br><div class="gmail_quote">On Fri, Jul 3, 2009 at 3:37 AM, Ole Streicher <span dir="ltr"><<a href="mailto:ole-usenet-spam@gmx.net">ole-usenet-spam@gmx.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hello Darren,<br>
<div class="im"><br>
Darren Dale <<a href="mailto:dsdale24@gmail.com">dsdale24@gmail.com</a>> writes:<br>
> Somebody reported some strange resizing behavior at the matplotlib mailing<br>
> list.<br>
<br>
</div>The "somebody" was me :-)<br>
<br>
Here some additional information:<br>
<br>
If you printout the resize (overwritten) events of the scrollbar and the<br>
matplotlib widgets (see code below), you will see that sometimes the<br>
events are not processed in-order:<br>
<br>
ScrollBar start 640<br>
ScrollBar end 640<br>
Diagram start 640<br>
Diagram end 640<br>
<br>
occurs when I just started, which is correct. But when one changes the<br>
horizontal size, the following happens (printouts which obviously belong<br>
to the same resize event are marked with the same number of stars):<br>
<br>
* Diagram start 633<br>
** Diagram start 608<br>
[...]<br>
** Diagram end 608<br>
** ScrollBar start 608<br>
** ScrollBar end 608<br>
* Diagram end 633<br>
* ScrollBar start 633<br>
* ScrollBar end 633<br>
<br>
What you see is that<br>
<br>
- the matplotlib FigureCanvasQTAgg gets its first resize event<br>
- during its processing inside FigureCanvasQTAgg a second event<br>
occurred<br>
- this second event is processed *faster* by FigureCanvasQTAgg than<br>
the first event<br>
- thus, the second event occurs *first* on the scrollbar<br>
- the first resize event only occurs after the second on the scrollbar<br>
- this leads to a wrong size of the scrollbar<br>
- this may occur even nested (removed "[...]" in the printout above)<br>
<br>
This may be a bug in FigureCanvasQTAgg (it is not synchonized in the<br>
processing of resize events, allowing events to bypass), or in<br>
Qt/QVBoxLayout (same argument there). I am not deep enough inside Qt to<br>
know the API details here.<br>
<br>
Best regards<br>
<br>
Ole<br>
-----------------------------8<------------------------------------------<br>
<div class="im">import sys<br>
<br>
from PyQt4 import QtGui, QtCore<br>
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg<br>
from matplotlib.figure import Figure<br>
<br>
</div>class MyDiagram(FigureCanvasQTAgg):<br>
def __init__(self, fig):<br>
FigureCanvasQTAgg.__init__(self, fig)<br>
<br>
def resizeEvent(self, event):<br>
print ' Diagram start', event.size().width()<br>
FigureCanvasQTAgg.resizeEvent(self, event)<br>
print ' Diagram end', event.size().width()<br>
<br>
<br>
class MyScrollBar(QtGui.QScrollBar):<br>
def __init__(self, parent):<br>
QtGui.QScrollBar.__init__(self, QtCore.Qt.Horizontal, parent)<br>
<br>
def resizeEvent(self, event):<br>
print 'ScrollBar start', event.size().width()<br>
QtGui.QScrollBar.resizeEvent(self, event)<br>
print 'ScrollBar end', event.size().width()<br>
<div class="im"><br>
class DiagramWidget(QtGui.QWidget):<br>
def __init__(self, parent=None):<br>
QtGui.QWidget.__init__(self, parent)<br>
<br>
</div> self.scrollbar = MyScrollBar(self)<br>
<div class="im"><br>
fig = Figure()<br>
axes = fig.add_subplot(111)<br>
axes.plot(xrange(100))<br>
</div> self.diagram = MyDiagram(fig)<br>
<div class="im"> self.diagram.setParent(self)<br>
<br>
layout = QtGui.QVBoxLayout(self)<br>
self.setLayout(layout)<br>
layout.addWidget(self.diagram)<br>
layout.addWidget(self.scrollbar)<br>
<br>
a = QtGui.QApplication(sys.argv)<br>
w = DiagramWidget()<br>
w.show()<br>
a.exec_()<br>
<br>
</div>-----------------------------8<------------------------------------------<br>
</blockquote><div><br><br>Nice demonstration of the problem Ole. I notice that if, after resizing, I pause briefly before releasing the mouse button, the scroll bar is more likely to resize properly. The problem is much more apparent if I release the mouse button immediately after resizing or while still dragging the window edge. <br>
<br>I also tried adding a call to qApp.processEvents() in FigureCanvasQT.resizeEvent, and that seemed to make the problem less frequent, but the problem still exists.<br></div></div><br>Darren<br>