HX_CoalFlowDetect/component/ZDateEdit/ztimeedit.cpp

67 lines
1.7 KiB
C++

#include "ztimeedit.h"
#include "QWidgetAction"
#include "dateCommonInfo.h"
#include <QFile>
#include <QHBoxLayout>
#include <QLineEdit>
#include <QMenu>
ZTimeEdit::ZTimeEdit(QWidget* parent)
: QTimeEdit(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, 20, 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, &ZTimeEdit::showCalendarWidget);
connect(m_pCldrWgt, &CalendarWidget::dayClicked, this, &ZTimeEdit::slotDayClicked);
QString tmp = displayFormat();
}
ZTimeEdit::~ZTimeEdit()
{
if (m_pCldrWgt) {
delete m_pCldrWgt;
}
}
void ZTimeEdit::showCalendarWidget()
{
QPoint pt(-17, height() - 10);
pt = mapToGlobal(pt);
m_pCldrWgt->jumpToDateTime(m_dateTime);
m_pCldrWgt->move(pt);
m_pCldrWgt->show();
}
void ZTimeEdit::slotDayClicked(const QDateTime& dt)
{
m_dateTime = dt;
setDateTime(dt);
}
void ZTimeEdit::setDisplayFormat(const QString& format)
{
m_pCldrWgt->setDisplayFormat(format);
QDateTimeEdit::setDisplayFormat(format);
}