0

I found a mouseDoubleClickEvent in QCalendarWidget, but it doesn't work on date cell. Is there a good solution?

l0o0
  • 773
  • 1
  • 9
  • 26

1 Answers1

1

[signal]void QCalendarWidget::activated(const QDate &date

This signal is emitted whenever the user presses the Return or Enter key or double-clicks a date in the calendar widget.

from PyQt5 import QtWidgets, QtCore


def activatedDate(date):
    print(date)
    

if __name__ == "__main__":
    import sys

    app = QtWidgets.QApplication(sys.argv)

    cal = QtWidgets.QCalendarWidget()
    
    cal.activated.connect(activatedDate)                 # <---
    
    fn = cal.font()
    fn.setPointSize(20)
    cal.setFont(fn)

    prev_button = cal.findChild(QtWidgets.QToolButton, "qt_calendar_prevmonth")
    next_button = cal.findChild(QtWidgets.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_())

enter image description here

Community
  • 1
  • 1
S. Nick
  • 12,879
  • 8
  • 25
  • 33