QDateEdit de;
de.setCalendarPopup(true); //设置日历弹出
de.setStyleSheet(QString("QDateEdit{border-radius: 6px;border: 1px solid #%1;padding:3px 0px 3px 6px;color: #000000;selection-background-color:#%1;}"
"QDateEdit::drop-down{border:none;}"
"QDateEdit::down-arrow{image: url(:xiala_black.png);border: none;}").arg(style_main_color));
QTextCharFormat format;//字体风格:黑色
format.setForeground(QColor(Qt::black));
QCalendarWidget * dateEditCalendarWidget = de.calendarWidget();
dateEditCalendarWidget->setWeekdayTextFormat(Qt::Saturday, format);
dateEditCalendarWidget->setWeekdayTextFormat(Qt::Sunday, format);
dateEditCalendarWidget->setFixedSize(500,300);
dateEditCalendarWidget->findChildren<QWidget*>().value(0)->setCursor(Qt::PointingHandCursor);
dateEditCalendarWidget->findChildren<QSpinBox*>().value(0)->setAlignment(Qt::AlignCenter);
dateEditCalendarWidget->findChildren<QSpinBox*>().value(0)->setButtonSymbols(QSpinBox::NoButtons);
QList<QToolButton * > toolbtn_list = de.calendarWidget()->findChildren<QToolButton*>();
for (int var = 0; var < toolbtn_list.size(); ++var)
{
toolbtn_list.value(var)->setCursor(Qt::PointingHandCursor);
}
QSize s = QSize(32,32);
QToolButton * toolbtn = de.calendarWidget()->findChild<QToolButton * >("qt_calendar_prevmonth");
toolbtn->setIcon(QPixmap(":left_ar.png"));
toolbtn->setIconSize(s);
toolbtn = de.calendarWidget()->findChild<QToolButton * >("qt_calendar_nextmonth");
toolbtn->setIcon(QPixmap(":right_ar.png"));
toolbtn->setIconSize(s);
de.calendarWidget()->setStyleSheet(QString("QCalendarWidget{background-color:#FFFFFF;border: 1px solid #%1;}"
"QCalendarWidget QAbstractItemView:enabled{color:#000000;"
"background-color:#ffffff;"
"selection-color: white;"
"selection-background-color:#%1;}"
"QCalendarWidget QSpinBox#qt_calendar_yearedit{background:#ffffff;height:34px;width:125px;selection-background-color:#%1;}"
"QCalendarWidget QToolButton{background-color:#FFFFFF;height:34px;width:125px;color:#000000;}"
"QCalendarWidget QToolButton:hover{border: 1px solid #%1;}"
"QCalendarWidget QToolButton::menu-indicator#qt_calendar_monthbutton{subcontrol-position: right center;subcontrol-origin: padding;}"
"QCalendarWidget QToolButton QMenu{background-color:#FFFFFF;width:125px;border:1px solid #%1;}"
"QCalendarWidget QToolButton QMenu::item:selected{color:#FFFFFF;background:#%1;}").arg(style_main_color));
de.setDate(QDate::currentDate());
de.setDisplayFormat("yyyy.MM.dd");
配合:Qt样式表:切换主题食用。