diff --git a/DateEditQSS/.gitignore b/DateEditQSS/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..fab7372d796ea95c80d02df6caa7eb2b411a7ac1 --- /dev/null +++ b/DateEditQSS/.gitignore @@ -0,0 +1,73 @@ +# This file is used to ignore files which are generated +# ---------------------------------------------------------------------------- + +*~ +*.autosave +*.a +*.core +*.moc +*.o +*.obj +*.orig +*.rej +*.so +*.so.* +*_pch.h.cpp +*_resource.rc +*.qm +.#* +*.*# +core +!core/ +tags +.DS_Store +.directory +*.debug +Makefile* +*.prl +*.app +moc_*.cpp +ui_*.h +qrc_*.cpp +Thumbs.db +*.res +*.rc +/.qmake.cache +/.qmake.stash + +# qtcreator generated files +*.pro.user* + +# xemacs temporary files +*.flc + +# Vim temporary files +.*.swp + +# Visual Studio generated files +*.ib_pdb_index +*.idb +*.ilk +*.pdb +*.sln +*.suo +*.vcproj +*vcproj.*.*.user +*.ncb +*.sdf +*.opensdf +*.vcxproj +*vcxproj.* + +# MinGW generated files +*.Debug +*.Release + +# Python byte code +*.pyc + +# Binaries +# -------- +*.dll +*.exe + diff --git a/DateEditQSS/DateEditQSS.pro b/DateEditQSS/DateEditQSS.pro new file mode 100644 index 0000000000000000000000000000000000000000..43c914883a0edb3b3646ac337919ed1a86cfcb19 --- /dev/null +++ b/DateEditQSS/DateEditQSS.pro @@ -0,0 +1,34 @@ +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +CONFIG += c++11 + +# The following define makes your compiler emit warnings if you use +# any Qt feature that has been marked deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + main.cpp \ + widget.cpp + +HEADERS += \ + widget.h + +FORMS += \ + widget.ui + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target + +RESOURCES += \ + src.qrc diff --git a/DateEditQSS/date_calendar.gif b/DateEditQSS/date_calendar.gif new file mode 100644 index 0000000000000000000000000000000000000000..7874abeece051f0c7ce4701f913781542837de32 Binary files /dev/null and b/DateEditQSS/date_calendar.gif differ diff --git a/DateEditQSS/image/calendar.png b/DateEditQSS/image/calendar.png new file mode 100644 index 0000000000000000000000000000000000000000..0260a2cdbfd3688cf9493167a9b39028cdc80713 Binary files /dev/null and b/DateEditQSS/image/calendar.png differ diff --git a/DateEditQSS/image/calendar_next_month.png b/DateEditQSS/image/calendar_next_month.png new file mode 100644 index 0000000000000000000000000000000000000000..91534039a409891e7030247188164cb6c6c53aaf Binary files /dev/null and b/DateEditQSS/image/calendar_next_month.png differ diff --git a/DateEditQSS/image/calendar_next_year.png b/DateEditQSS/image/calendar_next_year.png new file mode 100644 index 0000000000000000000000000000000000000000..6a45f850e9d714eb142dd648034e571033963d5f Binary files /dev/null and b/DateEditQSS/image/calendar_next_year.png differ diff --git a/DateEditQSS/image/calendar_pre_month.png b/DateEditQSS/image/calendar_pre_month.png new file mode 100644 index 0000000000000000000000000000000000000000..2643b39bf73ce1ef6795e2d47f141e9db6936391 Binary files /dev/null and b/DateEditQSS/image/calendar_pre_month.png differ diff --git a/DateEditQSS/image/calendar_pre_year.png b/DateEditQSS/image/calendar_pre_year.png new file mode 100644 index 0000000000000000000000000000000000000000..7b4c2d26f09cce65053dc9e8731b2eb08383cc57 Binary files /dev/null and b/DateEditQSS/image/calendar_pre_year.png differ diff --git a/DateEditQSS/main.cpp b/DateEditQSS/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b0a4ec26478f6b9aba3e1747ec464ea0c26dd5b9 --- /dev/null +++ b/DateEditQSS/main.cpp @@ -0,0 +1,11 @@ +#include "widget.h" + +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + Widget w; + w.show(); + return a.exec(); +} diff --git a/DateEditQSS/src.qrc b/DateEditQSS/src.qrc new file mode 100644 index 0000000000000000000000000000000000000000..03ad691d5e63a628cea826a36cc19872567802d3 --- /dev/null +++ b/DateEditQSS/src.qrc @@ -0,0 +1,9 @@ + + + image/calendar.png + image/calendar_next_month.png + image/calendar_next_year.png + image/calendar_pre_month.png + image/calendar_pre_year.png + + diff --git a/DateEditQSS/widget.cpp b/DateEditQSS/widget.cpp new file mode 100644 index 0000000000000000000000000000000000000000..483486934ac6c005e68843975bedfea95b020bd2 --- /dev/null +++ b/DateEditQSS/widget.cpp @@ -0,0 +1,67 @@ +#include "widget.h" +#include "ui_widget.h" + +Widget::Widget(QWidget *parent) + : QWidget(parent) + , ui(new Ui::Widget) + , labelTime(new QLabel("Date:")) + , dateStart(new QDateEdit) + , labelTo(new QLabel("-")) + , dateEnd(new QDateEdit) + , hLayMain(new QHBoxLayout) +{ + ui->setupUi(this); + + hLayMain->addWidget(labelTime); + hLayMain->addWidget(dateStart); + hLayMain->addWidget(labelTo); + hLayMain->addWidget(dateEnd); + hLayMain->addStretch(); + hLayMain->addStretch(); + setLayout(hLayMain); + + // set dateedit + dateStart->setCalendarPopup(true); + dateEnd->setCalendarPopup(true); + dateStart->setDate(QDate::currentDate()); + dateEnd->setDate(QDate::currentDate()); + + // set style + QString style = "QDateEdit{border: 1px solid #FFFFFF;border-radius: 3px;}" + "QDateEdit:hover{border: 1px solid #C0C4CC;}" + "QDateEdit::drop-down{" + "width: 15px;image: url(:/image/image/calendar.png);}" + "QCalendarWidget QWidget#qt_calendar_navigationbar{" + "background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,stop: 0 #313947, stop: 1 #34375E);}" + "QCalendarWidget QToolButton{" + "color: white;background-color: rgba(255, 255, 255, 0);}" + "QCalendarWidget QToolButton#qt_calendar_prevmonth{" + "qproperty-icon: url(:/image/image/calendar_pre_month.png);}" + "QCalendarWidget QToolButton#qt_calendar_nextmonth{" + "qproperty-icon: url(:/image/image/calendar_next_month.png);}" + "QCalendarWidget QSpinBox::up-button{" + "image: url(:/image/image/calendar_pre_year.png);" + "background-color: rgba(255, 255, 255, 100);" + "width:15px;}" + "QCalendarWidget QSpinBox::up-button:hover{" + "background-color: rgba(215, 218, 223, 100);}" + "QCalendarWidget QSpinBox::down-button{" + "image: url(:/image/image/calendar_next_year.png);" + "background-color: rgba(255, 255, 255, 100);" + "width:15px;}" + "QCalendarWidget QSpinBox::down-button:hover{" + "background-color: rgba(215, 218, 223, 100);}"; + dateStart->setStyleSheet(style); + dateEnd->setStyleSheet(style); +} + +Widget::~Widget() +{ + delete ui; + labelTime->deleteLater(); + dateStart->deleteLater(); + labelTo->deleteLater(); + dateEnd->deleteLater(); + hLayMain->deleteLater(); +} + diff --git a/DateEditQSS/widget.h b/DateEditQSS/widget.h new file mode 100644 index 0000000000000000000000000000000000000000..2918b329ba380d3b129414fce45c7f10fbb4f187 --- /dev/null +++ b/DateEditQSS/widget.h @@ -0,0 +1,30 @@ +#ifndef WIDGET_H +#define WIDGET_H + +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE +namespace Ui { class Widget; } +QT_END_NAMESPACE + +class Widget : public QWidget +{ + Q_OBJECT + +public: + Widget(QWidget *parent = nullptr); + ~Widget(); + +private: + Ui::Widget *ui; + + QLabel *labelTime; + QDateEdit *dateStart; + QLabel *labelTo; + QDateEdit *dateEnd; + QHBoxLayout *hLayMain; +}; +#endif // WIDGET_H diff --git a/DateEditQSS/widget.ui b/DateEditQSS/widget.ui new file mode 100644 index 0000000000000000000000000000000000000000..b90248d1302f26f09c3985b7150b73962bf5cbb0 --- /dev/null +++ b/DateEditQSS/widget.ui @@ -0,0 +1,19 @@ + + + Widget + + + + 0 + 0 + 800 + 600 + + + + Widget + + + + + diff --git a/README.md b/README.md index fd49db88d2eed8718cd6ff9250871b8661b307ae..e51f14f9b5c607267de6bf9de4dd9a1d009f0e3c 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ JTabWidgetDemo | 无 | QTabWidget基本操作和样式设置 JMainFrame | 无 | Qt搭建软件框架 DxfGraphics | dxflib | 基于 GraphicsView 显示线 TabScorllArea | | 仿照网易云音乐设置界面实现滚动显示设置界面 +DateEditQSS | | QSS 改造 QDateEdit、QCalendarWidget @@ -146,3 +147,12 @@ TabScorllArea | | 仿照网易云音乐设置界面实现滚动显示设置 3. 使用按钮快速定位 ![scroll_setting.gif](https://i.loli.net/2020/04/09/Fq6HxEnSIbto5W7.gif "scroll setting") + +## DateEditQSS 2020-4-15 +> QSS 改造 QDateEdit、QCalendarWidget +1. 使用 QSS 重新搭配 QDateEdit,并下拉弹出 QCalendarWidget +2. QCalendarWidget 表头设置渐变色,使用图标设置上/下个月按钮 +3. QCalendarWidget 年选择设置图标按钮并修改样式 + +![date_calendar.gif](https://i.loli.net/2020/04/15/6CdRyQM7fzKFsb4.gif "QDateEdit") +