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

Avoid showing a black background before the plot is ready with Qt5agg backend #19755

Closed
hppi-johnsson opened this issue Mar 21, 2021 · 2 comments
Labels
Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues GUI: Qt Maintenance status: upstream fix required
Milestone

Comments

@hppi-johnsson
Copy link

When I open a window to show a plot, the background of the canvas is first black for some time until the plot is ready. This can be up to several seconds for large datasets.
This is just a cosmetic annoyance, since the user experiences a "flickering" of the window.

I am using using Matplotlib 3.3.4 with Qt5 on Windows 10.
In an older release I used before (1.4.2 with Qt4) the window is not shown until the plot is ready, so the issue is never seen.

I suggest that the background color of the widget is shown before the plot is drawn.

@tacaswell tacaswell added Good first issue Open a pull request against these issues if there are no active ones! Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues labels Mar 24, 2021
@tacaswell
Copy link
Member

This is somelpace in the Qt widget start up code. It is a good first issue as there is no API design discussion required and I suspect very little understanding of Matplotlib internals required, but medium difficulty as it will requires knowing how the Qt APIs work and reading through our GUI setup code.

It is possible that the black coloring is coming from Qt and is drawn before we have any chance to influence it, but I would be surprised.

@tacaswell tacaswell added this to the v3.5.0 milestone Mar 24, 2021
@QuLogic QuLogic added status: upstream fix required and removed Good first issue Open a pull request against these issues if there are no active ones! labels Jul 9, 2021
@QuLogic
Copy link
Member

QuLogic commented Jul 9, 2021

I experimented with this, and there is unfortunately nothing we can do without a fix occurring in Qt.

According to Qt docs, Windows are filled with the QPalette::Window colour unless the WA_OpaquePaintEvent attribute is set. This attribute is set on the canvas, but not on the window. You can also set QWidget::autoFillBackground to do the same.

Using QPalette or setStyleSheet, you can see that it's effective by the toolbar changing backgrounds (but not the canvas, since we draw that all ourselves). However, when things are slow, even the toolbar is initially drawn in black, disregarding the stylesheet or palette.

So we can't really do anything about this without a change in Qt.

@QuLogic QuLogic closed this as completed Jul 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues GUI: Qt Maintenance status: upstream fix required
Projects
None yet
Development

No branches or pull requests

3 participants