Results 1 to 7 of 7

Thread: QCalendarWidget::clicked

  1. #1
    Join Date
    Feb 2010
    Posts
    61
    Thanks
    18
    Qt products
    Qt4
    Platforms
    MacOS X

    Default QCalendarWidget::clicked

    Hi,

    one can read the following in the documentation:

    This signal is emitted when a mouse button is clicked. The date the mouse was clicked on is specified by date. The signal is only emitted when clicked on a valid date, e.g., dates are not outside the minimumDate() and maximumDate(). If the selection mode is NoSelection, this signal will not be emitted.
    Is there a more flexible way to define what a valid date is ? For example if I would like the signal to be emitted only when a business week is selected, e.g., nothing happens when one clicks on Saturday or Sunday ?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QCalendarWidget::clicked

    You can subclass like that:
    Qt Code:
    1. class MyCalendarWidget: public QCalendarWidget
    2. {
    3. Q_OBJECT
    4. public:
    5. MyCalendarWidget(QWidget* parent) : QCalendarWidget(parent)
    6. {
    7. QObject::connect(this, SIGNAL(clicked(const QDate&)), this, SLOT(checkClicked(const QDate&)));
    8. }
    9.  
    10. private Q_SLOTS:
    11. void checkClicked(const QDate& date) const
    12. {
    13. if (Qt::Saturday != date.dayOfWeek()
    14. && Qt::Sunday != date.dayOfWeek())
    15. Q_EMIT myClicked(date);
    16. }
    17.  
    18. Q_SIGNALS:
    19. void myClicked(const QDate&);
    20. };
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Feb 2010
    Posts
    61
    Thanks
    18
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: QCalendarWidget::clicked

    Thank you Lykurg . I created a subclass as you said except that I set the parent to 0 (I don't see which other value it might be...).

    Then I replaced the default calendar of my QDateEdit with the new one as follows:

    Qt Code:
    1. CalendarWidget calendarWidget = new CalendarWidget;
    2. myDateEdit->setCalendarWidget(calendarWidget);
    To copy to clipboard, switch view to plain text mode 

    But I obtain an error message at run time:

    QDateTimeEdit::setCalendarWidget: calendarPopup is set to false

    Do you see what am I doing wrong ?

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QCalendarWidget::clicked

    Quote Originally Posted by ouekah View Post
    But I obtain an error message at run time:

    QDateTimeEdit::setCalendarWidget: calendarPopup is set to false
    And what's the problem? It is only a warning and it says what is going on! just use
    Qt Code:
    1. myDateEdit->setCalendarPopup(true);
    To copy to clipboard, switch view to plain text mode 
    to activate the popup functionality!

  5. The following user says thank you to Lykurg for this useful post:

    ouekah (26th April 2010)

  6. #5
    Join Date
    Feb 2010
    Posts
    61
    Thanks
    18
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: QCalendarWidget::clicked

    This was done already ! That's why it looked weird to me... But actually in my code this instruction was executed AFTER QDateTimeEdit::setCalendarWidget. When the latter is executed if it finds out that QDateTimeEdit:: calendarPopup is set to false, it generates the so called warning...

    Thanks for your help...

  7. #6
    Join Date
    Feb 2010
    Posts
    61
    Thanks
    18
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: QCalendarWidget::clicked

    Is there away to prevent some dates to be selected like with QCalendarWidget::setDateRange ?

    I have a calendar in which some dates (chosen randomly) should not be selected and I cannot use setDateRange neither setMaximumDate neither setMinimumDate to achieve that. By subclassing QCalendarWidget and redefining what happens on a click, I prevent the user to send a forbidden date to the application. But it is still possible to select a forbidden date in my calendar even if nothing happens then.

    With QCalendarWidget::setDateRange, the user cannot select a date outside the range. And this is exactly the effect that I would like to reproduce.

    Does anyone know if there is a way to do that without creating a calendar widget from scracth ?

  8. #7
    Join Date
    Feb 2010
    Posts
    61
    Thanks
    18
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: QCalendarWidget::clicked

    I have no idea dude

Similar Threads

  1. How to capture right clicked dates in a QCalendarWidget?
    By balazsbela in forum Qt Programming
    Replies: 1
    Last Post: 21st February 2010, 13:36
  2. How can I add a QCalendarWidget to a QToolBar?
    By cydside in forum Qt Programming
    Replies: 1
    Last Post: 10th April 2009, 23:06
  3. How to set Style sheet for QCalendarWidget?
    By nifei in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2009, 22:36
  4. about QCalendarWidget
    By nifei in forum Qt Programming
    Replies: 2
    Last Post: 9th February 2009, 09:17
  5. No QCalendarWidget in designer? 4.2.0-tp1
    By Spockmeat in forum Qt Tools
    Replies: 2
    Last Post: 9th August 2006, 18:13

Bookmarks

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.