Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Bug]: Negative figure size in QSplitter. #25566

Copy link
Copy link
Open
@Abbath

Description

@Abbath
Issue body actions

Bug summary

I use matplotlib + PyQt5. The figure is placed inside a QSplitter (a standard Qt widget that consists of several vertical or horizontal parts which the handles between those parts can resize). When a part of QSplitter shrinks to a zero size it automatically resizes the widget it contains. I already had an issue with this (#17093) but now I have a new one.

When there are other widgets in the same splitter part with a figure the figure becomes negatively sized.
image
Here a splitter consists of two parts: the top one with one button and the bottom one with a figure and a button in a vertical layout. When I pull the split line all the way down I get an exception that the figure has a negative size.

Code for reproduction

import sys

from PyQt5.QtWidgets import QMainWindow, QApplication, QVBoxLayout

from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure

from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(800, 600)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
        self.gridLayout.setObjectName("gridLayout")
        self.splitter = QtWidgets.QSplitter(self.centralwidget)
        self.splitter.setOrientation(QtCore.Qt.Vertical)
        self.splitter.setObjectName("splitter")
        self.pushButton = QtWidgets.QPushButton(self.splitter)
        self.pushButton.setObjectName("pushButton")
        self.widget = QtWidgets.QWidget(self.splitter)
        self.widget.setObjectName("widget")
        self.verticalLayout = QtWidgets.QVBoxLayout(self.widget)
        self.verticalLayout.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout.setObjectName("verticalLayout")
        self.plot = QtWidgets.QWidget(self.widget)
        self.plot.setObjectName("plot")
        self.verticalLayout.addWidget(self.plot)
        self.pushButton_2 = QtWidgets.QPushButton(self.widget)
        self.pushButton_2.setObjectName("pushButton_2")
        self.verticalLayout.addWidget(self.pushButton_2)
        self.gridLayout.addWidget(self.splitter, 0, 0, 1, 1)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 32))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.pushButton.setText(_translate("MainWindow", "PUSH"))
        self.pushButton_2.setText(_translate("MainWindow", "PUSH2"))

class MainWindow(QMainWindow):
    def __init__(self, *args):
        super().__init__(*args)

        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        self.figure = Figure()
        self.canvas = FigureCanvas(self.figure)

        layout = QVBoxLayout()
        layout.addWidget(self.canvas)
        self.ui.plot.setLayout(layout)

app = QApplication(sys.argv)

mw = MainWindow()
mw.show()

app.exec()

Actual outcome

ValueError: figure size must be positive finite not [ 7.76 -0.06]

Expected outcome

Not seeing an exception.

Additional information

No response

Operating system

Kubuntu 22.04

Matplotlib Version

3.7.1

Matplotlib Backend

QtAgg

Python version

Python 3.10.6

Jupyter version

No response

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.