HX_CoalFlowDetect/component/ZDateEdit/zdatetimeedit.cpp

67 lines
1.8 KiB
C++
Raw Normal View History

2024-11-04 18:11:55 +08:00
#include "zdatetimeedit.h"
#include "QWidgetAction"
#include "dateCommonInfo.h"
#include <QFile>
#include <QHBoxLayout>
#include <QLineEdit>
#include <QMenu>
ZDateTimeEdit::ZDateTimeEdit(QWidget* parent)
: QDateTimeEdit(parent)
{
m_popupButton = new QPushButton();
m_popupButton->setObjectName("popupButton");
//m_popupButton->setText("+");
//m_popupButton->setCursor(Qt::ArrowCursor);
QHBoxLayout* layout = new QHBoxLayout();
m_popupButton->setCursor(QCursor(Qt::PointingHandCursor));
layout->addStretch();
layout->addWidget(m_popupButton);
layout->setContentsMargins(0, 0, 2, 0);
this->setLayout(layout);
QFile file(":/component/ZDateEdit/qss/zDateTimeEdit.qss");
if (file.open(QFile::ReadOnly)) {
QString qss = file.readAll();
setStyleSheet(qss);
file.close();
}
m_pCldrWgt = new CalendarWidget(displayFormat(), this, QMenu().windowFlags() | Qt::FramelessWindowHint);
m_dateTime = QDateTime::currentDateTime();
setDateTime(m_dateTime);
connect(m_popupButton, &QAbstractButton::clicked, this, &ZDateTimeEdit::showCalendarWidget);
connect(m_pCldrWgt, &CalendarWidget::dayClicked, this, &ZDateTimeEdit::slotDayClicked);
QString tmp = displayFormat();
}
ZDateTimeEdit::~ZDateTimeEdit()
{
if (m_pCldrWgt) {
delete m_pCldrWgt;
}
}
void ZDateTimeEdit::showCalendarWidget()
{
QPoint pt(0, height() + 5);
pt = mapToGlobal(pt);
m_pCldrWgt->jumpToDateTime(m_dateTime);
m_pCldrWgt->move(pt);
m_pCldrWgt->show();
}
void ZDateTimeEdit::slotDayClicked(const QDateTime& dt)
{
m_dateTime = dt;
setDateTime(dt);
}
void ZDateTimeEdit::setDisplayFormat(const QString& format)
{
m_pCldrWgt->setDisplayFormat(format);
QDateTimeEdit::setDisplayFormat(format);
}