资源简介
完全自绘制日历控件,日期位置和日期数字都是在内容中计算,之前已经有两个关于自绘制日历的demo,但这个demo功能有所增强,主要是支持月份切换,记录当前选中日期等
代码片段和文件信息
#include “stdafx.h“
#include “DrawDateTime.h“
#include “CalendarWidget.h“
namespace
{
QString dataDescribe(unsigned short year unsigned short month)
{
QString result;
result.append(QString::number(year));
result.append(QStringLiteral(“年“));
if (month < 10)
{
result.append(QStringLiteral(“0“));
result.append(QString::number(month));
}
else
{
result.append(QString::number(month));
}
result.append(QStringLiteral(“月“));
return result;
}
}
struct CalendarWidgetPrivate
{
unsigned short m_wYear = 2016;
unsigned short m_wMonth = 11;
unsigned short m_wDay = 14;
QPushButton * m_pPrevisou = nullptr;
QLabel * m_pMonth = nullptr;
QPushButton * m_pNext = nullptr;
DrawDateTime * m_pDataView = nullptr;
};
CalendarWidget::CalendarWidget(QWidget * parent)
: QWidget(parent)
d_ptr(new CalendarWidgetPrivate)
{
InitializeUI();
}
CalendarWidget::~CalendarWidget()
{
}
void CalendarWidget::InitializeUI()
{
QVBoxLayout * mainLayout = new QVBoxLayout;
mainLayout->setSpacing(0);
mainLayout->setMargin(0);
QHBoxLayout * titleLayout = new QHBoxLayout;
d_ptr->m_pPrevisou = new QPushButton;
d_ptr->m_pMonth = new QLabel;
d_ptr->m_pNext = new QPushButton;
titleLayout->setSpacing(0);
titleLayout->setMargin(0);
d_ptr->m_pPrevisou->setText(QStringLiteral(“previous“));
d_ptr->m_pMonth->setText(dataDescribe(d_ptr->m_wYear d_ptr->m_wMonth));
d_ptr->m_pNext->setText(QStringLiteral(“next“));
titleLayout->addWidget(d_ptr->m_pPrevisou);
titleLayout->addWidget(d_ptr->m_pMonth);
titleLayout->addWidget(d_ptr->m_pNext);
mainLayout->addLayout(titleLayout);
d_ptr->m_pDataView = new DrawDateTime;
connect(d_ptr->m_pDataView &DrawDateTime::DataClicked this [this](unsigned short year unsigned short month unsigned short day){
emit DataClicked(year month day);
d_ptr->m_pMonth->setText(dataDescribe(year month));
// setHidden(true);
});
connect(d_ptr->m_pPrevisou &QPushButton::clicked this [this]{
d_ptr->m_pDataView->PreviousMonth();
d_ptr->m_pDataView->GetDate(d_ptr->m_wYear d_ptr->m_wMonth d_ptr->m_wDay);
d_ptr->m_pMonth->setText(dataDescribe(d_ptr->m_wYear d_ptr->m_wMonth));
});
connect(d_ptr->m_pNext &QPushButton::clicked this [this]{
d_ptr->m_pDataView->NextMonth();
d_ptr->m_pDataView->GetDate(d_ptr->m_wYear d_ptr->m_wMonth d_ptr->m_wDay);
d_ptr->m_pMonth->setText(dataDescribe(d_ptr->m_wYear d_ptr->m_wMonth));
});
d_ptr->m_pDataView->SetDate(d_ptr->m_wYear d_ptr->m_wMonth d_ptr->m_wDay);
mainLayout->addWidget(d_ptr->m_pDataView);
setLayout(mainLayout);
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2016-11-14 20:12 DropDataControl\
文件 2682 2016-11-14 18:33 DropDataControl\CalendarWidget.cpp
文件 464 2016-11-14 17:49 DropDataControl\CalendarWidget.h
文件 10652 2016-11-14 20:12 DropDataControl\DrawDateTime.cpp
文件 1013 2016-11-14 18:20 DropDataControl\DrawDateTime.h
文件 2258 2016-11-14 18:41 DropDataControl\DropDataControl.cpp
文件 425 2016-11-14 17:38 DropDataControl\DropDataControl.h
文件 2734 2016-02-02 16:42 DropDataControl\DropDataControl.ico
文件 75 2016-11-14 17:24 DropDataControl\DropDataControl.qrc
文件 54 2016-11-14 17:24 DropDataControl\DropDataControl.rc
文件 14657 2016-11-14 18:01 DropDataControl\DropDataControl.vcxproj
文件 3732 2016-11-14 17:50 DropDataControl\DropDataControl.vcxproj.filters
目录 0 2016-11-15 19:30 DropDataControl\Resources\
文件 218 2016-11-14 17:25 DropDataControl\main.cpp
文件 21 2016-11-14 17:24 DropDataControl\stdafx.cpp
文件 22 2016-11-14 17:24 DropDataControl\stdafx.h
- 上一篇:Qt之自定义检索框
- 下一篇:基于mapreduce的并行算法的设计 课件
评论
共有 条评论