简体   繁体   English

PyQt5 日历小部件子项

[英]PyQt5 Calendar Widget Children

I want to change the style of the calendar widget;我想更改日历小部件的样式; however, I couldn't change the background of the months drop-down menu (which I guess is ComboBox).Also there are some dark gray rects at the sides of the 'Dec 2021' text.但是,我无法更改月份下拉菜单的背景(我猜是 ComboBox)。此外,“Dec 2021”文本的两侧还有一些深灰色的矩形。 How could I change them, too?我怎么能改变他们呢? Thanks in advance.提前致谢。

Here is what I've done so far;这是我到目前为止所做的;

self.dateEdit.setStyleSheet(
        f"QDateEdit{{font-size: {int(settings['FONT_SIZE_PRIMARY']*0.6)}px; font-family: {settings['FONT']};\
    color: {settings['COLOR_PRIMARY']};background-color: {settings['COLOR_BG_PRIMARY']};}}"
        f"QCalendarWidget{{font-size: {int(settings['FONT_SIZE_SECONDARY']*0.7)}px;\
        font-family: {settings['FONT']};}}"
        f"QAbstractItemView{{background-color: {settings['COLOR_PRIMARY']};}}"
    )

日历小部件

The month selection popup is actually a QMenu, so you need to use the appropriate selector.月份选择弹窗其实是一个QMenu,所以需要使用合适的选择器。

The navigation bar has a hardcoded object name ( qt_calendar_navigationbar ), so you can use the #id selector.导航栏有一个硬编码的 object 名称 ( qt_calendar_navigationbar ),因此您可以使用#id选择器。

QMenu {
    background: orange;
}
QMenu::item:selected {
    background: yellow;
    border-radius: 2px;
}
#qt_calendar_navigationbar {
    background: rgb(255, 168, 88)
}

All buttons in the navigation bar have object names (always have a look at the sources to check for those), so you can style them individually:导航栏中的所有按钮都有 object 名称(始终查看源以检查这些名称),因此您可以单独设置它们的样式:

  • qt_calendar_prevmonth
  • qt_calendar_nextmonth
  • qt_calendar_monthbutton
  • qt_calendar_yearbutton
  • qt_calendar_yearedit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM