Results 1 to 2 of 2

Thread: Right Click a QCalendarWidget date

  1. #1
    Join Date
    Oct 2016
    Qt products

    Default Right Click a QCalendarWidget date

    Hi, my application currently implements a QCalendarWidget and when a user clicks any date a QMenu popup to choose an option:

    Qt Code:
    1. connect(this, SIGNAL(clicked(QDate)), this, SLOT(dateSelected(QDate)));
    3. ...
    5. void CalendarManagerRep::dateSelected(const QDate &date)
    6. {
    7. m_selectedDate = date;
    8. QMenu menu;
    9. menu.addAction("0",this, SLOT(noSelection()));
    10. menu.addAction("½",this, SLOT(halfSelected()));
    11. menu.addAction("1",this, SLOT(oneSelected()));
    12. menu.exec(QCursor::pos());
    14. auto view = this->findChild<QAbstractItemView*>();
    15. if(view){
    16. view->viewport()->update();
    17. } else update(); // fallback
    19. emit datesChanged();
    20. }
    To copy to clipboard, switch view to plain text mode 

    Now I would like to move the QMenu on the right-click and leave left-click for a default value.

    I tried to reimplement void QWidget::mouseReleaseEvent(QMouseEvent *event) but it seems to trigger only when right-clicking the calendar header.

    Any clue? Very thanks

  2. #2
    Join Date
    Jan 2008
    Alameda, CA, USA
    Thanked 854 Times in 841 Posts
    Qt products

    Default Re: Right Click a QCalendarWidget date

    You might have to derive a new class from QCalendarWidget and override some of the mouse handling. My guess is that the widget eats the mouse events and converts them into the other signals.

    For starters, you could implement an event filter then use the debugger to see what happens in response to the mousePresseEvent and mouseReleaseEvent events. I imagine a complex widget like this could be pretty easy to break if you start adding custom handling for events.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 2
    Last Post: 30th August 2019, 21:16
  2. Replies: 1
    Last Post: 10th March 2014, 13:25
  3. Replies: 1
    Last Post: 5th March 2014, 01:41
  4. Replies: 1
    Last Post: 24th April 2010, 16:31
  5. How to default Date-Edit Widget to system date
    By JohnToddSr in forum Qt Tools
    Replies: 4
    Last Post: 17th January 2007, 20:18

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.