I am facing a problem regarding the coloration of a specific date on my QWidgetCalender. I
have to subclass QCalenderWidget and to reimplement de function painCell. What I did. And I have called
the function paintCell in my appropriate window, but I have this error message:
Error : no matching function for call to 'MyCalender:
aintCell(QPainter*&, <unresolved overloaded function type>, const QDate&)'
Candidates are: virtual void MyCalender:
aintCell(QPainter*, const QRect&, const QDate&)
What am I doing wrong?
Many thanks in advance.
Here is my code:
I subclass here QCalenderWidget and I reimplement paintCell:
{
public:
~MyCalender();
protected:
};
{
}
{
if(date.dayOfWeek() == Qt::Monday)
{
painter->save();
painter->fillRect(rect, Qt::green);
painter->drawRect(rect);
painter
->drawText
(rect, Qt
::AlignCenter,
QString::number(date.
day()));
painter->restore();
}
else
{
}
}
class MyCalender: public QCalendarWidget
{
public:
MyCalender(QWidget *parent);
~MyCalender();
protected:
virtual void paintCell(QPainter *painter, const QRect &rect, const QDate &date);
};
MyCalender::MyCalender(QWidget *parent): QCalendarWidget(parent)
{
}
void MyCalender::paintCell(QPainter *painter, const QRect &rect, const QDate &date)
{
if(date.dayOfWeek() == Qt::Monday)
{
painter->save();
painter->fillRect(rect, Qt::green);
painter->drawRect(rect);
painter->drawText(rect, Qt::AlignCenter, QString::number(date.day()));
painter->restore();
}
else
{
QCalendarWidget::paintCell(painter, rect, date);
}
}
To copy to clipboard, switch view to plain text mode
My Window:
{
Q_OBJECT
public:
~MyWindow();
public slots:
void colorADate
(const QDate &date
);
private:
MyCalender *m_calendrier;
};
void MyWindow
::colorADate(const QDate &date
) {
m_calendrier->paintCell(painter, rect, date);
}
class MyWindow: public QDialog
{
Q_OBJECT
public:
MyWindow(QWidget *parent = 0);
~MyWindow();
QString getFileName();
public slots:
void colorADate(const QDate &date);
private:
MyCalender *m_calendrier;
};
void MyWindow::colorADate(const QDate &date)
{
QPainter *painter = new QPainter;
m_calendrier->paintCell(painter, rect, date);
}
To copy to clipboard, switch view to plain text mode
Bookmarks