- QDateEdit点击弹出日历控件
方法一:在界面中勾选属性
方法二:或在在cpp文件中设置ui->dateEdit->setCalendarPopup(true);
- 让QDateEdit显示当前时间
ui->dateEdit->setDisplayFormat("yyyy-MM-dd");
ui->dateEdit->setDateTime(QDateTime::currentDateTime());
- 设置QDateEdit弹出日历的样式
其实弹出的是QCalendarWidget控件,设置它的样式即可
我使用的样式表直接设置,样式见下图
QCalendarWidget QWidget#qt_calendar_navigationbar { background-color: #696969; }
QCalendarWidget QToolButton {
height: 30px;
color: white;
font-size: 24px;
icon-size: 56px, 56px;
background-color: #696969;
}
QCalendarWidget QSpinBox {
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; }
QCalendarWidget QSpinBox::down-button {subcontrol-origin: border; subcontrol-position: bottom right; }
QCalendarWidget QAbstractItemView:enabled
{
font-size:24px;
}
QCalendarWidget QAbstractItemView:disabled { color: rgb(64, 64, 64); }