Skip to content

GraphicsLayout: Always call layout.activate() after adding items#1173

Merged
j9ac9k merged 1 commit intopyqtgraph:developfrom
2xB:fix-1136-2
May 30, 2020
Merged

GraphicsLayout: Always call layout.activate() after adding items#1173
j9ac9k merged 1 commit intopyqtgraph:developfrom
2xB:fix-1136-2

Conversation

@2xB
Copy link
Copy Markdown
Contributor

@2xB 2xB commented Apr 14, 2020

When items are added to a GraphicsLayout items in the layout only learn their updated 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.

Testing code used next to MWE from issues below:

import pyqtgraph as pg
pg.mkQApp()

win = pg.GraphicsLayoutWidget()
win.show()

p1 = pg.PlotItem()
p2 = pg.PlotItem()
win.addItem(p1, None, None, 1, 1)
win.resize(800,800)
win.addItem(p2, None, None, 1, 1)
# pg.QtGui.QApplication.processEvents() # <-- workaround
print(p1.boundingRect()) # Should return something slightly smaller than (0,0,400,800)
print(p2.boundingRect()) # Should return something slightly smaller than (0,0,400,800)

Fixes #8
Fixes #1136

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 pyqtgraph#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 pyqtgraph#1167.

Fixes pyqtgraph#8
Fixes pyqtgraph#1136
@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented May 30, 2020

Closing/Re-Opening to trigger new CI runs now that we're skipping pg.exit() on Qt 5.9

@j9ac9k j9ac9k closed this May 30, 2020
@j9ac9k j9ac9k reopened this May 30, 2020
@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented May 30, 2020

Thanks for the PR @2xB this looks good to me, and the CI system agrees!

@j9ac9k j9ac9k merged commit 2ac1eef into pyqtgraph:develop May 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

an issue on ViewBox.mapToView Avoid export bug by calling processEvents() before export

2 participants