From ec66c34fc90fb18d2ed3b40fba2b63779a3f0e63 Mon Sep 17 00:00:00 2001 From: 2xB <2xB@users.noreply.github.com> Date: Tue, 14 Apr 2020 01:37:09 +0200 Subject: [PATCH] GraphicsLayout: Always call layout.activate() after adding items Items added to a `GraphicsLayout` only learn their size information after the internal `QGraphicsGridLayout` recalculates the layout. This is happening as a slot in the Qt event queue. Not having updated geometry bounds directly after adding an item leads to multiple issues when not executing the Qt event loop in time (see below). This commit fixes that by always calling `layout.activate()` after adding items, updating item sizes directly. This is a follow-up to PR #1167, where introducing a direct call to `processEvents` was suspected to be able to cause side effects. Notifying @j9ac9k and @campagnola, as they were involved in #1167. Fixes #8 Fixes #1136 --- pyqtgraph/graphicsItems/GraphicsLayout.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyqtgraph/graphicsItems/GraphicsLayout.py b/pyqtgraph/graphicsItems/GraphicsLayout.py index c3722ec0..9c209352 100644 --- a/pyqtgraph/graphicsItems/GraphicsLayout.py +++ b/pyqtgraph/graphicsItems/GraphicsLayout.py @@ -134,6 +134,9 @@ class GraphicsLayout(GraphicsWidget): item.geometryChanged.connect(self._updateItemBorder) self.layout.addItem(item, row, col, rowspan, colspan) + self.layout.activate() # Update layout, recalculating bounds. + # Allows some PyQtGraph features to also work without Qt event loop. + self.nextColumn() def getItem(self, row, col):