QCalendarWidgetで月曜日、火曜日、水曜日、木曜日、または金曜日(平日)を選択できるようにします。しかし、土曜日や日曜日ではありません。 (週末)QCalendarWidgetで土曜日と日曜日を無効にすることはできますか?
- この機能はQCalendarWidgetで利用できますか?
- そうでない場合は、カレンダーの日付を無効にするにはどうすればよいですか?
QCalendarWidgetで月曜日、火曜日、水曜日、木曜日、または金曜日(平日)を選択できるようにします。しかし、土曜日や日曜日ではありません。 (週末)QCalendarWidgetで土曜日と日曜日を無効にすることはできますか?
カスタムのCalendarWidgetを書き、必要に応じてセルを再ペイントすることができます。あなたの要求として、date.dayOfWeek()
が6または7であることを確認できます。
この例では、日付が平日の場合はカレンダーウィジェットが色を変更でき、週末の場合は変更されません。しかし、ウィジェットカレンダーはまだイベントclicked
を取得します。この助けを願っています。
TestCalendar.h
class TestCalendar: public QCalendarWidget//: public QWidget//
{
Q_OBJECT
Q_PROPERTY(QColor color READ getColor WRITE setColor)
public:
TestCalendar(QWidget* parent = 0);//();//
~TestCalendar();
void setColor(QColor& color);
QColor getColor();
protected:
virtual void paintCell(QPainter* painter, const QRect &rect, const QDate &date) const;
private:
QDate m_currentDate;
QPen m_outlinePen;
QBrush m_transparentBrush;
};
TestCalendar.cpp
#include <QtWidgets>
#include "TestCalendar.h"
TestCalendar::TestCalendar(QWidget *parent)
: QCalendarWidget(parent)
{
m_currentDate = QDate::currentDate();
m_outlinePen.setColor(Qt::blue);
m_transparentBrush.setColor(Qt::transparent);
}
TestCalendar::~TestCalendar()
{
}
void TestCalendar::setColor(QColor &color)
{
m_outlinePen.setColor(color);
}
QColor TestCalendar::getColor()
{
return m_outlinePen.color();
}
void TestCalendar::paintCell(QPainter *painter, const QRect &rect, const QDate &date) const
{
if (date.dayOfWeek() == 6 or date.dayOfWeek() == 7) {
painter->save();
painter->drawText(rect, Qt::AlignCenter,QString::number(date.day()));
painter->restore();
} else {
QCalendarWidget::paintCell(painter, rect, date);
}
}
EDIT:
@eyllanescを追加しますが、まあ、ないより漠然と以上質問。 – user0042
解決策は確定していないようですので、答えは無効だと思いますので、私は終了投票を削除します。 – eyllanesc