我正在尝试将一些样式表应用到我的QCalendarWidget中,并且我已经做了一些更改。下面是我目前的代码:
QCalendarWidget QWidget{
background-color:magenta;
color: green;
}
QCalendarWidget QToolButton{
background-color:black;
color: green;
icon-size: 30px;
}
QCalendarWidget QMenu{
background-color:magenta;
color: green;
}
QCalendarWidget QAbstractItemView:enabled{
background-color: yellow;
color: black;
}
QCalendarWidget QAbstractItemView:disabled{
background-color: yellow;
color: white;
}
QCalendarWidget QMenu{
background-color: rgb(255, 46, 221);
}
QCalendarWidget QSpinBox{
background-color: black;
}结果是这样的:

问题是我找不到如何自定义绿色箭头、星期数和星期几。有什么建议吗?
发布于 2019-07-17 11:29:55
这只适用于month按钮,有点老生常谈,而且要记住它是基于硬编码的私有方法。它使用objectName来获取特定的QToolButton ("qt_calendar_prevmonth“和"qt_calendar_nextmonth")并设置图标。不要使用image: url,因为它不适用于QToolButtons。
从理论上讲,您还可以通过检查标题的布局并检查第一个和最后一个QToolButtons来找到它们的对象名称,这可能会有点“困难”,但可能更安全,然后,您可以相应地设置样式表。
#qt_calendar_prevmonth {
background-color: blue;
icon-size: 30px;
qproperty-icon: url(prevmonth.svg);
}
#qt_calendar_nextmonth {
background-color: orange;
icon-size: 30px;
qproperty-icon: url(nextmonth.svg);
}不幸的是,由于QCalendarWidget的工作方式,无法通过样式表更改"headers“的格式,因此您需要坚持使用QCalendarWidget的headerTextFormat()、dateTextFormat()等。
fmt = cal.headerTextFormat()
fmt.setForeground(QtGui.QColor('green'))
fmt.setBackground(QtGui.QColor('orange'))
cal.setHeaderTextFormat(fmt)https://stackoverflow.com/questions/57049775
复制相似问题