Skip to content

Cannot remove the legend from a visible plot window #96

@igortg

Description

@igortg

insertLegend(None) does not remove the legend if show() is already been called.

from PyQt5.QtWidgets import QApplication
from qwt import QwtPlot, QwtPlotCurve, QwtLegend

app = QApplication([])

plot = QwtPlot()
legend = QwtLegend()
plot.insertLegend(legend, plot.TopLegend)

x_values = list(range(0, 10))
curve = QwtPlotCurve("Curve")
curve.setData(x_values, x_values)
curve.attach(plot)

plot.updateAxes()
plot.show()
# Remove the legend
plot.insertLegend(None)

app.exec()

Calling legend.setParent(None) before insertLegend(None) fix the issue and the legend is removed accordingly. If show is called before inserLegend(None), it also works correctly.

PythonQwt: 0.14.4
PyQt: 5.15.11

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions