QCalendarWidget qss样式设置

在Qt项目中为了实现不同的样式,于是把所有控件的样式都写为QSS文件中,遇到了QCalendarWidget一脸懵逼

QCalendarWidget的是有好几个控件组成的,那么为了设置其样式表,只要分别设置的组成其的所有控件的样式即可搞定,

为了获取每个控件的objectName 有两种方式,1.通过源码,找到QCalendarWidget的源文件,如果在安装Qt时,选择安装了源码,可以找到每个控件的名称,2.如果没有安装源码,还有一种方式,通过循环打印出QCalendarWidget的里面的控件:

(object->metaObject()->className()) //类名

(object->objectName());

//类名对应的控件别名,如果object有子类,则QObjectList list = object->children();循坏输出下,从而得到所有的控件类名和对应别名,然后分别设置其样式,函数得详细内容,可以参考下面这位作者的博客:

https://qtdebug.com/qtbook-qss-calendar/

下面附上从一个Qt centre http://www.qtcentre.org/threads/30478-How-To-Change-Style-Sheet-for-QCalendarWidget()里面找到的一个样式例子以供参考:

/* navigation bar */
QCalendarWidget QWidget#qt_calendar_navigationbar { background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop: 0 #cccccc, stop: 1 #333333); }
QCalendarWidget QToolButton {
    height: 60px;
    width: 150px;
    color: white;
    font-size: 24px;
    icon-size: 56px, 56px;
    background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop: 0 #cccccc, stop: 1 #333333);
}
QCalendarWidget QMenu {
    width: 150px;
    left: 20px;
    color: white;
    font-size: 18px;
    background-color: rgb(100, 100, 100);
}
QCalendarWidget QSpinBox {
    width: 150px;
    font-size:24px;
    color: white;
    background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop: 0 #cccccc, stop: 1 #333333);
    selection-background-color: rgb(136, 136, 136);
    selection-color: rgb(255, 255, 255);
}
QCalendarWidget QSpinBox::up-button { subcontrol-origin: border;  subcontrol-position: top right;  width:65px; }
QCalendarWidget QSpinBox::down-button {subcontrol-origin: border; subcontrol-position: bottom right;  width:65px;}
QCalendarWidget QSpinBox::up-arrow { width:56px;  height:56px; }
QCalendarWidget QSpinBox::down-arrow { width:56px;  height:56px; }
 
/* header row */
QCalendarWidget QWidget { alternate-background-color: rgb(128, 128, 128); }
 
/* normal days */
QCalendarWidget QAbstractItemView:enabled
{
    font-size:24px;  
    color: rgb(180, 180, 180);  
    background-color: black;  
    selection-background-color: rgb(64, 64, 64);
    selection-color: rgb(0, 255, 0);
}
 
/* days in other months */
QCalendarWidget QAbstractItemView:disabled { color: rgb(64, 64, 64); }

 


原文链接:https://blog.csdn.net/u010311553/article/details/80705268

posted on 2021-06-08 14:16  回形针的迷宫  阅读(1387)  评论(0编辑  收藏  举报

导航