How to create a custom calender widget/bg: Difference between revisions
Jump to navigation
Jump to search
AutoSpider (talk | contribs) (Convert ExpressionEngine links) |
AutoSpider (talk | contribs) (Decode HTML entity names) |
||
Line 33: | Line 33: | ||
protected: | protected: | ||
void paintCell(QPainter *painter, const QRect & | void paintCell(QPainter *painter, const QRect &rect, const QDate &date) const | ||
{ | { | ||
if ( ) // our conditions | if ( ) // our conditions |
Revision as of 17:19, 12 March 2015
This article may require cleanup to meet the Qt Wiki's quality standards. Reason: Auto-imported from ExpressionEngine. Please improve this article if you can. Remove the {{cleanup}} tag and add this page to Updated pages list after it's clean. |
Български English
Промяна на външния вид на QCalendarWidget
Има много различни начини, по които може да се направи календар. Най-лесният би бил чрез използване на QCalendarWidget. Обаче този клас предоставя ограничен контрол над външния вид.
Този проблем може да бъде разрешен чрез наследяване на QCalendarWidget. Приложен е примерен клас, който обяснява модифициран календар.
Клетките, или отделните дни са персонализирани и за да направим това контролираме метода paintCell, който е protected.
Пример:
class ourCalendarWidget : public QCalendarWidget
{
Q_OBJECT
public:
ourCalendarWidget(QWidget *parent = 0) : QCalendarWidget(parent){}
~ourCalendarWidget() {}
void ourCall(QDate date)
{
// here we set some conditions
update();
}
protected:
void paintCell(QPainter *painter, const QRect &rect, const QDate &date) const
{
if ( ) // our conditions
{ // When the conditions are matched, passed QDate is drawn as we like.
painter->save();
painter->drawEllipse(rect); // here we draw n ellipse and the day—
painter->drawText(rec, Qt::TextSingleLine, Qt::AlignCenter,QString::number(date.day()));
painter->restore();
}
else
{ // if our conditions are not matching, show the default way.
QCalendarWidget::paintCell(painter, rect, date);
}
}