我想自定义QCalendarWidget
,我无法更改禁用状态的周末颜色。这就是它现在的样子:
我想把红色变灰。我知道您可以使用以下方式设置周末颜色:
QTextCharFormat weekendFormat;
weekendFormat.setForeground(QBrush(Qt::green, Qt::SolidPattern));
m_ui->calendarWidget->setWeekdayTextFormat(Qt::Saturday, weekendFormat);
m_ui->calendarWidget->setWeekdayTextFormat(Qt::Sunday, weekendFormat);
但这不会影响禁用状态。如何影响禁用状态并为周末设置不同的禁用颜色?
谢谢!
答案 0 :(得分:1)
如果要为启用和禁用状态获取不同的颜色,可以子类化并重新实现更改事件处理程序:
void MyCalendar::changeEvent(QEvent *event)
{
QCalendarWidget::changeEvent(event);
if (event->type() == QEvent::EnabledChange)
{
QColor color;
if (isEnabled())
{
color = Qt::blue;
}
else
{
color = Qt::yellow;
}
QTextCharFormat weekendFormat;
weekendFormat.setForeground(QBrush(color, Qt::SolidPattern));
setWeekdayTextFormat(Qt::Saturday, weekendFormat);
setWeekdayTextFormat(Qt::Sunday, weekendFormat);
}
}