Search code examples
pythonpython-2.7pyqtpyqt4qcalendarwidget

making qt calendar arrows larger


I use the QCalendarWidget to create a calendar.

I made the calendar and its font larger, but I don't know how to make the arrows of the calendar larger too. By arrows, I mean to the green ones at the top, that let you go back and forth.

I am working with python 2.7, and using PyQt4.

creating the calendar using the QCalendarWidget -

    cal = QtGui.QCalendarWidget(self)

IMAGE: You could see that the arrows are not proportional to the calendar's size.

enter image description here


Solution

  • One possible solution is to set the iconSize qproperty with Qt Style Sheet:

    from PyQt4 import QtGui
    
    if __name__ == "__main__":
        import sys
    
        app = QtGui.QApplication(sys.argv)
    
        cal = QtGui.QCalendarWidget()
        fn = cal.font()
        fn.setPointSize(20)
        cal.setFont(fn)
    
        cal.setStyleSheet("""
            #qt_calendar_prevmonth, #qt_calendar_nextmonth{
                qproperty-iconSize: 40px
            }
        """
        )
    
        cal.resize(640, 480)
        cal.show()
        sys.exit(app.exec_())
    

    Another possible solution is to access each button using findChild and set the iconSize:

    from PyQt4 import QtCore, QtGui
    
    if __name__ == "__main__":
        import sys
    
        app = QtGui.QApplication(sys.argv)
    
        cal = QtGui.QCalendarWidget()
        fn = cal.font()
        fn.setPointSize(20)
        cal.setFont(fn)
    
        prev_button = cal.findChild(QtGui.QToolButton, "qt_calendar_prevmonth")
        next_button = cal.findChild(QtGui.QToolButton, "qt_calendar_nextmonth")
        for btn in (prev_button, next_button):
            btn.setIconSize(QtCore.QSize(40, 40))
    
        cal.resize(640, 480)
        cal.show()
        sys.exit(app.exec_())