Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何定制QCalendarWidget?_Python_Python 3.x_Pyqt5_Pyside2_Qcalendarwidget - Fatal编程技术网

Python 如何定制QCalendarWidget?

Python 如何定制QCalendarWidget?,python,python-3.x,pyqt5,pyside2,qcalendarwidget,Python,Python 3.x,Pyqt5,Pyside2,Qcalendarwidget,我正在尝试将一些样式表应用到我的QCalendarWidget,我已经做了一些更改。这是我目前的代码: QCalendarWidget QWidget{ background-color:magenta; color: green; } QCalendarWidget QToolButton{ background-color:black; color: green; icon-size: 30px; } QCalendarWidget QMenu{ background-color:ma

我正在尝试将一些样式表应用到我的
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;
}
结果是:


问题是我找不到如何自定义绿色箭头、周数和周天数。有什么建议吗?

这只适用于月份按钮,有点粗糙,请记住它是基于硬编码的私有方法。它使用objectName获取特定的QToolButton(“qt_calendar_prevmonth”和“qt_calendar_nextmonth”),并设置图标。不要使用
image:url
,因为它不适用于QToolButtons

从理论上讲,您也可以通过浏览标题的布局并检查第一个和最后一个QToolButtons来找到它们的对象名,这可能有点“难”,但可能更安全,之后,您可以相应地设置样式表

#qt_日历(上个月){
背景颜色:蓝色;
图标大小:30px;
qproperty图标:url(prevmonth.svg);
}
#qt\u日历\u下个月{
背景颜色:橙色;
图标大小:30px;
qproperty图标:url(nextmonth.svg);
}
不幸的是,由于QCalendarWidget的工作方式,无法通过样式表更改“headers”的格式,因此您需要坚持使用QCalendarWidget的headerTextFormat()、dateTextFormat()等等

fmt = cal.headerTextFormat()
fmt.setForeground(QtGui.QColor('green'))
fmt.setBackground(QtGui.QColor('orange'))
cal.setHeaderTextFormat(fmt)

更好地解释一下,你想从绿色箭头中改变什么?您想在“周数”和“周天数”中更改什么?我想更改绿色箭头的图标和背景,以及周数和周天数的背景、字体大小和样式。