diff --git a/bin/defaultstyle.qss b/bin/defaultstyle.qss index eb5b7fd..369d1a5 100644 --- a/bin/defaultstyle.qss +++ b/bin/defaultstyle.qss @@ -134,4 +134,6 @@ QPushButton#open background: #0d9ddb; border-radius:10px; padding:7px 10px; -} \ No newline at end of file +} + + diff --git a/bin/xyylMCWEACSystem.exe b/bin/xyylMCWEACSystem.exe index 02f4cb1..db5feb1 100644 Binary files a/bin/xyylMCWEACSystem.exe and b/bin/xyylMCWEACSystem.exe differ diff --git a/xyylMCWEACSystem/cdateedit.cpp b/xyylMCWEACSystem/cdateedit.cpp new file mode 100644 index 0000000..e61abb4 --- /dev/null +++ b/xyylMCWEACSystem/cdateedit.cpp @@ -0,0 +1,187 @@ +#include "CDateEdit.h" + +class CDateEdit::Private { +public: + Private(CDateEdit* qq) : q(qq), null(false), nullable(false) {} + + CDateEdit* const q; + + bool null; + bool nullable; + + void setNull(bool n) { + null = n; + if (null) { + QLineEdit *edit = q->findChild("qt_spinbox_lineedit"); + if (!edit->text().isEmpty()) { + edit->clear(); + } + } + } +}; + +CDateEdit::CDateEdit(QWidget *parent) : +QDateEdit(parent), d(new Private(this)) +{ +} + +QDateTime CDateEdit::dateTime() const +{ + if (d->nullable && d->null) { + return QDateTime(); + } + else { + return QDateEdit::dateTime(); + } +} + +QDate CDateEdit::date() const +{ + if (d->nullable && d->null) { + return QDate(); + } + else { + return QDateEdit::date(); + } +} + +QTime CDateEdit::time() const +{ + if (d->nullable && d->null) { + return QTime(); + } + else { + return QDateEdit::time(); + } +} + +void CDateEdit::setDateTime(const QDateTime &dateTime) +{ + if (d->nullable && !dateTime.isValid()) { + d->setNull(true); + } + else { + d->setNull(false); + QDateEdit::setDateTime(dateTime); + } +} + +void CDateEdit::setDate(const QDate &date) +{ + if (d->nullable && !date.isValid()) { + d->setNull(true); + } + else { + d->setNull(false); + QDateEdit::setDate(date); + } +} + +void CDateEdit::setTime(const QTime &time) +{ + if (d->nullable && !time.isValid()) { + d->setNull(true); + } + else { + d->setNull(false); + QDateEdit::setTime(time); + } +} + +bool CDateEdit::isNullable() const +{ + return d->nullable; +} + +void CDateEdit::setNullDatetime() +{ + d->setNull(true); +} + +void CDateEdit::setNullable(bool enable) +{ + d->nullable = enable; + + update(); +} + +QSize CDateEdit::sizeHint() const +{ + const QSize sz = QDateEdit::sizeHint(); + return QSize(sz.width() + 3, sz.height()); +} + +QSize CDateEdit::minimumSizeHint() const +{ + const QSize sz = QDateEdit::minimumSizeHint(); + return QSize(sz.width() + 3, sz.height()); +} + +void CDateEdit::showEvent(QShowEvent *event) +{ + QDateEdit::showEvent(event); + d->setNull(d->null); +} + +void CDateEdit::resizeEvent(QResizeEvent *event) +{ + QDateEdit::resizeEvent(event); +} + +void CDateEdit::paintEvent(QPaintEvent *event) +{ + d->setNull(d->null); + QDateEdit::paintEvent(event); + +} + +void CDateEdit::keyPressEvent(QKeyEvent *event) +{ + if (d->nullable && + (event->key() >= Qt::Key_0) && + (event->key() <= Qt::Key_9) && + d->null) { + setDateTime(QDateTime::currentDateTime()); + } + if (event->key() == Qt::Key_Tab && d->nullable && d->null) { + QAbstractSpinBox::keyPressEvent(event); + return; + } + if (event->key() == Qt::Key_Backspace && d->nullable){ + QLineEdit *edit = this->findChild("qt_spinbox_lineedit"); + if (edit->selectedText() == edit->text()) { + setDateTime(QDateTime()); + event->accept(); + return; + } + } + + QDateEdit::keyPressEvent(event); +} + +void CDateEdit::mousePressEvent(QMouseEvent *event) +{ + bool saveNull = d->null; + QDateEdit::mousePressEvent(event); + if (d->nullable && saveNull && calendarWidget()->isVisible()) { + setDateTime(QDateTime::currentDateTime()); + } +} + +bool CDateEdit::focusNextPrevChild(bool next) +{ + if (d->nullable && d->null){ + return QAbstractSpinBox::focusNextPrevChild(next); + } + else { + return QDateEdit::focusNextPrevChild(next); + } +} + +QValidator::State CDateEdit::validate(QString &input, int &pos) const +{ + if (d->nullable && d->null){ + return QValidator::Acceptable; + } + return QDateEdit::validate(input, pos); +} diff --git a/xyylMCWEACSystem/cdateedit.h b/xyylMCWEACSystem/cdateedit.h new file mode 100644 index 0000000..ea643b1 --- /dev/null +++ b/xyylMCWEACSystem/cdateedit.h @@ -0,0 +1,54 @@ +#ifndef CDATEEDIT_H +#define CDATEEDIT_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +class CDateEdit : public QDateEdit +{ + + Q_OBJECT + +public: + explicit CDateEdit(QWidget *parent = 0); + + QDateTime dateTime() const; + QDate date() const; + QTime time() const; + + bool isNullable() const; + void setNullable(bool enable); + void setNullDatetime(); + + QSize sizeHint() const; + QSize minimumSizeHint() const; + +protected: + void showEvent(QShowEvent *event); + void resizeEvent(QResizeEvent *event); + void paintEvent(QPaintEvent *event); + void keyPressEvent(QKeyEvent *event); + void mousePressEvent(QMouseEvent *event); + bool focusNextPrevChild(bool next); + QValidator::State validate(QString &input, int &pos) const; + +public slots: + void setDateTime(const QDateTime &dateTime); + void setDate(const QDate &date); + void setTime(const QTime &time); + +private: + Q_DISABLE_COPY(CDateEdit) + class Private; + friend class Private; + Private* d; + +}; + +#endif // CDATEEDIT_H diff --git a/xyylMCWEACSystem/egg.qrc b/xyylMCWEACSystem/egg.qrc index 8d96dc6..84c1f8c 100644 --- a/xyylMCWEACSystem/egg.qrc +++ b/xyylMCWEACSystem/egg.qrc @@ -67,5 +67,9 @@ image/data.png image/img_BEAM.png image/setup.png + image/dateEdit.png + image/dateEdit_disable.png + image/dateEdit_hover.png + image/dateEdit_pressed.png diff --git a/xyylMCWEACSystem/image/dateEdit.png b/xyylMCWEACSystem/image/dateEdit.png new file mode 100644 index 0000000..34ff737 Binary files /dev/null and b/xyylMCWEACSystem/image/dateEdit.png differ diff --git a/xyylMCWEACSystem/image/dateEdit_disable.png b/xyylMCWEACSystem/image/dateEdit_disable.png new file mode 100644 index 0000000..1819ede Binary files /dev/null and b/xyylMCWEACSystem/image/dateEdit_disable.png differ diff --git a/xyylMCWEACSystem/image/dateEdit_hover.png b/xyylMCWEACSystem/image/dateEdit_hover.png new file mode 100644 index 0000000..c738c0a Binary files /dev/null and b/xyylMCWEACSystem/image/dateEdit_hover.png differ diff --git a/xyylMCWEACSystem/image/dateEdit_pressed.png b/xyylMCWEACSystem/image/dateEdit_pressed.png new file mode 100644 index 0000000..56ab7ec Binary files /dev/null and b/xyylMCWEACSystem/image/dateEdit_pressed.png differ diff --git a/xyylMCWEACSystem/main.cpp b/xyylMCWEACSystem/main.cpp index b8cf198..f0a6e30 100644 --- a/xyylMCWEACSystem/main.cpp +++ b/xyylMCWEACSystem/main.cpp @@ -26,6 +26,9 @@ qApp->setStyleSheet(sqss); qss.close(); } +#include "cdateedit.h" +#include "test.h" +#include int main(int argc, char *argv[]) { QApplication a(argc, argv); @@ -46,5 +49,28 @@ int main(int argc, char *argv[]) LoadStyleFile(QApplication::applicationDirPath()+"/defaultstyle.qss"); #endif +#if 1 + QDateTimeEdit date; + date.setStyleSheet("QDateTimeEdit::drop-down {\ + width: 80px; \ + border-left-width: 0px; \ + border-image:url(:/image/dateEdit.png);\ + border-left-color: gray; \ + }"); + date.setCalendarPopup(true); + + date.show(); +#else + QDateEdit date; + date.setDisplayFormat("yyyy-MM-dd hh:mm:ss.zzz"); + date.setStyleSheet("QDateEdit::drop-down {\ + width: 80px; \ + border-left-width: 0px; \ + border-image:url(:/image/dateEdit.png);\ + border-left-color: gray; \ + }"); + date.setCalendarPopup(true); + date.show(); +#endif return a.exec(); } diff --git a/xyylMCWEACSystem/medicalrecordwidget.cpp b/xyylMCWEACSystem/medicalrecordwidget.cpp index 8b1e7fb..60e10fe 100644 --- a/xyylMCWEACSystem/medicalrecordwidget.cpp +++ b/xyylMCWEACSystem/medicalrecordwidget.cpp @@ -32,7 +32,27 @@ void MedicalRecordWidget::init() m_labStar.setObjectName("labStar"); m_labStar2.setText(tr("*")); m_labStar2.setObjectName("labStar"); + m_dateInspection.setCalendarPopup(true); + m_dateBirthDay.setCalendarPopup(true); + m_dateBirthDay.setDisplayFormat("yyyy-MM-dd"); + m_dateInspection.setDisplayFormat("yyyy-MM-dd"); + QDateTime currentDateTime = QDateTime::currentDateTime(); + QString formattedDateTime = currentDateTime.toString("yyyy-MM-dd"); + m_dateInspection.setDateTime(QDateTime::fromString(formattedDateTime, "yyyy-MM-dd")); + m_dateBirthDay.setDateTime(QDateTime::fromString(formattedDateTime, "yyyy-MM-dd")); + m_dateBirthDay.setStyleSheet("QDateEdit::drop-down {\ + width: 80px; \ + border-left-width: 1px; \ + border-image:url(:/image/dateEdit.png);\ + border-left-color: gray; \ + }"); + m_dateInspection.setStyleSheet("QDateEdit::drop-down {\ + width: 80px; \ + border-left-width: 1px; \ + border-image:url(:/image/dateEdit.png);\ + border-left-color: gray; \ + }"); #if 0 #else @@ -270,6 +290,39 @@ void MedicalRecordWidget::initLay() vlayAll->addWidget(w); vlayAll->addLayout(hlay_okCancel); setLayout(vlayAll); + + m_btnOk.setStyleSheet("QPushButton{width: 180px;height: 64px;\ + background: white;\ + border-radius:12px;padding:7px 10px;\ + }\ + QPushButton:hover{width: 180px;height: 64px;\ + background: #0d9ddb;\ + border-radius:12px;padding:7px 10px;\ + }\ + QPushButton:pressed{width: 180px;height: 64px;\ + background: #0d9ddb;\ + border-radius:12px;padding:7px 10px;\ + }\ + QPushButton:checked{width: 180px;height: 64px;\ + background: #0d9ddb;\ + border-radius:12px;padding:7px 10px;\ + }"); + m_btnCancel.setStyleSheet("QPushButton{width: 180px;height: 64px;\ + background: white;\ + border-radius:12px;padding:7px 10px;\ + }\ + QPushButton:hover{width: 180px;height: 64px;\ + background: #0d9ddb;\ + border-radius:12px;padding:7px 10px;\ + }\ + QPushButton:pressed{width: 180px;height: 64px;\ + background: #0d9ddb;\ + border-radius:12px;padding:7px 10px;\ + }\ + QPushButton:checked{width: 180px;height: 64px;\ + background: #0d9ddb;\ + border-radius:12px;padding:7px 10px;\ + }"); #endif diff --git a/xyylMCWEACSystem/medicalrecordwidget.h b/xyylMCWEACSystem/medicalrecordwidget.h index d981e27..af2f657 100644 --- a/xyylMCWEACSystem/medicalrecordwidget.h +++ b/xyylMCWEACSystem/medicalrecordwidget.h @@ -16,6 +16,7 @@ #include #include #include +#include class MedicalRecordWidget:public QWidget { Q_OBJECT @@ -54,6 +55,7 @@ private: //年龄 QLabel m_labAge; QLineEdit m_editAge; + //左右利 QLabel m_labLaterality; QRadioButton m_chLeft; diff --git a/xyylMCWEACSystem/xyylMCWEACSystem.pro b/xyylMCWEACSystem/xyylMCWEACSystem.pro index 2e72a56..5db6e30 100644 --- a/xyylMCWEACSystem/xyylMCWEACSystem.pro +++ b/xyylMCWEACSystem/xyylMCWEACSystem.pro @@ -31,6 +31,7 @@ SOURCES += \ SqlExecute.cpp \ SqlGenerate.cpp \ btngroupwidget.cpp \ + cdateedit.cpp \ curchatwidget.cpp \ datamanager.cpp \ dataprocesswidget.cpp \ @@ -53,6 +54,7 @@ SOURCES += \ parametersettingswidget.cpp \ regwidget.cpp \ systemsettingwidget.cpp \ + test.cpp \ titlewidget.cpp \ widget.cpp @@ -62,6 +64,7 @@ HEADERS += \ SqlExecute.h \ SqlGenerate.h \ btngroupwidget.h \ + cdateedit.h \ curchatwidget.h \ datamanager.h \ dataprocesswidget.h \ @@ -83,6 +86,7 @@ HEADERS += \ parametersettingswidget.h \ regwidget.h \ systemsettingwidget.h \ + test.h \ titlewidget.h \ widget.h