Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Getting mouse events with QCalendarWidget
Forum Update on Monday, May 27th 2025

Getting mouse events with QCalendarWidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
qcalendarwidget
3 Posts 3 Posters 1.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nathaniel
    wrote on 20 May 2016, 04:37 last edited by
    #1

    Here's some lines of QCalendarView::mouseReleaseEvent:

    void QCalendarView::mouseReleaseEvent(QMouseEvent *event)
    {
    ...
    if (event->button() != Qt::LeftButton)
    return;
    ...
    }

    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?

    R 1 Reply Last reply 20 May 2016, 05:40
    0
    • N Nathaniel
      20 May 2016, 04:37

      Here's some lines of QCalendarView::mouseReleaseEvent:

      void QCalendarView::mouseReleaseEvent(QMouseEvent *event)
      {
      ...
      if (event->button() != Qt::LeftButton)
      return;
      ...
      }

      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?

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 20 May 2016, 05:40 last edited by
      #2

      @Nathaniel
      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 );
      

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SergSk
        wrote on 9 Jun 2023, 17:08 last edited by
        #3

        Not QTableView
        You should use
        findChild<QTableView*>("qt_calendar_calendarview")->viewport()->installEventFilter(this);

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved