Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QCalendarWidget does not update calendar when month changes on Mac OSX



  • When the user clicks the left or right arrow buttons to switch months, the calendar does not update its view. Weirdly, clicking individual date causes the clicked item to be updated.

    To reproduce:

    try:
        from PyQt5.QtWidgets import *
    except ImportError:
        from PySide2.QtWidgets import *
    app = QApplication([])
    control = QMainWindow(None)
    control.setVisible(True)
    calendar = QCalendarWidget(control)
    control.setCentralWidget(calendar)
    app.exec_()
    

    Jul-06-2020 11-25-42.gif
    Changing the month by selecting it from the dropdown does not suffer from this problem.
    This seems to affect Mac OSX only, as I have tested this with Windows and Linux and have not observed the same issue.
    I am not sure if this is an issue of the Python wrapper, or a bug for Qt?

    System information:
    OSX 10.15.5
    Python 3.8

    Other packages:
    pip 19.2.3
    PySide2 5.15.0
    setuptools 41.2.0
    shiboken2 5.15.0

    For reference, this looks/feels like the issue in https://forum.qt.io/topic/107558/push-buttons-and-pixmaps-not-updating-refreshing-properly-in-pyqt-only-on-macos/7

    With that, I was able to "workaround" by adding setEnabled(False) and setEnabled(True) somehow when the layout change event occurs:

    try:
        from PyQt5 import QtCore
        from PyQt5.QtWidgets import *
    except ImportError:
        from PySide2 import QtCore
        from PySide2.QtWidgets import *
    
    class MyFilter(QtCore.QObject):
        def eventFilter(self, object, event):
            if event.type() == QtCore.QEvent.LayoutRequest:
                object.setEnabled(False)
                object.setEnabled(True)
            return super().eventFilter(object, event)
    
    app = QApplication([])
    control = QMainWindow(None)
    control.setVisible(True)
    calendar = QCalendarWidget(control)
    
    filter_ = MyFilter()
    calendar.installEventFilter(filter_)
    
    control.setCentralWidget(calendar)
    app.exec_()
    

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    On macOS 10.13.6, I have the situation in the other direction. The selection does not follow at all when changing the month.

    I saw there were patches going in for the model used by this widget so I wonder if this behaviour will change.


Log in to reply