更新日期控件和样式
This commit is contained in:
parent
c5f64d5a6b
commit
7e993e2a77
@ -134,4 +134,6 @@ QPushButton#open
|
||||
background: #0d9ddb;
|
||||
border-radius:10px;
|
||||
padding:7px 10px;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Binary file not shown.
187
xyylMCWEACSystem/cdateedit.cpp
Normal file
187
xyylMCWEACSystem/cdateedit.cpp
Normal file
@ -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<QLineEdit*>("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<QLineEdit *>("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);
|
||||
}
|
54
xyylMCWEACSystem/cdateedit.h
Normal file
54
xyylMCWEACSystem/cdateedit.h
Normal file
@ -0,0 +1,54 @@
|
||||
#ifndef CDATEEDIT_H
|
||||
#define CDATEEDIT_H
|
||||
|
||||
#include <QtCore>
|
||||
#include <QWidget>
|
||||
#include <QDateEdit>
|
||||
#include <QStyle>
|
||||
#include <QPushButton>
|
||||
#include <QLineEdit>
|
||||
#include <QStyleOptionSpinBox>
|
||||
#include <QKeyEvent>
|
||||
#include <QCalendarWidget>
|
||||
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
|
@ -67,5 +67,9 @@
|
||||
<file>image/data.png</file>
|
||||
<file>image/img_BEAM.png</file>
|
||||
<file>image/setup.png</file>
|
||||
<file>image/dateEdit.png</file>
|
||||
<file>image/dateEdit_disable.png</file>
|
||||
<file>image/dateEdit_hover.png</file>
|
||||
<file>image/dateEdit_pressed.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
BIN
xyylMCWEACSystem/image/dateEdit.png
Normal file
BIN
xyylMCWEACSystem/image/dateEdit.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
BIN
xyylMCWEACSystem/image/dateEdit_disable.png
Normal file
BIN
xyylMCWEACSystem/image/dateEdit_disable.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.0 KiB |
BIN
xyylMCWEACSystem/image/dateEdit_hover.png
Normal file
BIN
xyylMCWEACSystem/image/dateEdit_hover.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.0 KiB |
BIN
xyylMCWEACSystem/image/dateEdit_pressed.png
Normal file
BIN
xyylMCWEACSystem/image/dateEdit_pressed.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
@ -26,6 +26,9 @@
|
||||
qApp->setStyleSheet(sqss);
|
||||
qss.close();
|
||||
}
|
||||
#include "cdateedit.h"
|
||||
#include "test.h"
|
||||
#include<QDateEdit>
|
||||
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();
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include <QTextEdit>
|
||||
#include <QGroupBox>
|
||||
#include <QRadioButton>
|
||||
#include <QDateTimeEdit>
|
||||
class MedicalRecordWidget:public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -54,6 +55,7 @@ private:
|
||||
//年龄
|
||||
QLabel m_labAge;
|
||||
QLineEdit m_editAge;
|
||||
|
||||
//左右利
|
||||
QLabel m_labLaterality;
|
||||
QRadioButton m_chLeft;
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user