Getting mouse events with QCalendarWidget

  • Here's some lines of QCalendarView::mouseReleaseEvent:

    void QCalendarView::mouseReleaseEvent(QMouseEvent *event)
    if (event->button() != Qt::LeftButton)

    Why is QCalendarView just ignoring other mouse events? Why not at least emit a signal? I've noticed several questions about right-clicks in QCalendarTableWidget. Why not skip the return at least for event->button() == Qt::RightButton but then (after confirming a valid date) emit a signal like (say) rightClicked(const QDate), alongside the existing code which selects a date and then emits clicked(const QDate)? This seems unusually sloppy for Qt ... Also, even if you try to intercept mousePressEvent by subclassing QCalendarTableWidget you're only getting the override function called for mouse events on screen areas which are not occupied by the TableView, like the top-left corner area, right of the "Sunday".

    Is the idea that we're supposed to get a reference to the QTableView parent of the QCalendarView and connect to signals from that?

  • Moderators

    why do you believe this is "sloppy"?! Actually it is the exact difference.
    In common UX concepts you select only with left mouse button and show a context menu with right mouse button.

    To get events you can install an eventfilter on the view:

    calendarWidget->findChild<QTableView*>("qt_calendar_calendarview")->installEventFilter( this );

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.