PDA

View Full Version : QCalendarWidget::clicked



ouekah
24th April 2010, 10:55
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 ?

Lykurg
24th April 2010, 11:06
You can subclass like that:
class MyCalendarWidget: public QCalendarWidget
{
Q_OBJECT
public:
MyCalendarWidget(QWidget* parent) : QCalendarWidget(parent)
{
QObject::connect(this, SIGNAL(clicked(const QDate&)), this, SLOT(checkClicked(const QDate&)));
}

private Q_SLOTS:
void checkClicked(const QDate& date) const
{
if (Qt::Saturday != date.dayOfWeek()
&& Qt::Sunday != date.dayOfWeek())
Q_EMIT myClicked(date);
}

Q_SIGNALS:
void myClicked(const QDate&);
};

ouekah
24th April 2010, 11:54
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:



CalendarWidget calendarWidget = new CalendarWidget;
myDateEdit->setCalendarWidget(calendarWidget);


But I obtain an error message at run time:

QDateTimeEdit::setCalendarWidget: calendarPopup is set to false

Do you see what am I doing wrong ?

Lykurg
25th April 2010, 10:08
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
myDateEdit->setCalendarPopup(true);to activate the popup functionality!

ouekah
26th April 2010, 09:33
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...

ouekah
27th April 2010, 14:57
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 ?

ouekah
2nd May 2010, 16:37
I have no idea dude