Qt学习十:日历组件
2016-06-30 17:52
471 查看
日历组件 qtButton.h如下:
#ifndef QTBUTTON_H
#define QTBUTTON_H
#include <QtWidgets/QMainWindow>
#include "ui_qtbutton.h"
//---------日历组件----------------------
#include<qlabel.h>
#include<qlineedit.h>
#include<qcalendarwidget.h>
class qtButton : public QMainWindow
{
Q_OBJECT
public:
qtButton(QWidget *parent = 0);
~qtButton();
private:
Ui::qtButtonClass ui;
//-------------日历组件--------------------
QLabel *label;
QLineEdit *lineEdit;
QCalendarWidget *calendarWidget;
private slots:
//-----------日历组件---------
void showTime();
void setData();
};
#endif // QTBUTTON_H
qtButton.cpp如下
#include "qtbutton.h"
//------------------------------
qtButton::qtButton(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
//-----------日历组件---------
label = new QLabel(this);
label->setText("choose data:");
label->setGeometry(QRect(50, 50, 100, 25));
lineEdit = new QLineEdit(this);
lineEdit->setGeometry(QRect(130, 50, 150, 22));
connect(lineEdit, SIGNAL(cursorPositionChanged(int, int)), this, SLOT(showTime()));
calendarWidget = new QCalendarWidget(this);
calendarWidget->setGeometry(20, 75, 350, 180);
calendarWidget->setHidden(true);
connect(calendarWidget, SIGNAL(clicked(QDate)), this, SLOT(setData));
}
qtButton::~qtButton()
{
}
void qtButton::showTime()
{
calendarWidget->setHidden(false);
}
void qtButton::setData()
{
QDate date = calendarWidget->selectedDate();
QString str = date.toString("yyyy-MM-dd");
lineEdit->setText(str);
calendarWidget->setHidden(true);
}
最后程序运行结果为:
#ifndef QTBUTTON_H
#define QTBUTTON_H
#include <QtWidgets/QMainWindow>
#include "ui_qtbutton.h"
//---------日历组件----------------------
#include<qlabel.h>
#include<qlineedit.h>
#include<qcalendarwidget.h>
class qtButton : public QMainWindow
{
Q_OBJECT
public:
qtButton(QWidget *parent = 0);
~qtButton();
private:
Ui::qtButtonClass ui;
//-------------日历组件--------------------
QLabel *label;
QLineEdit *lineEdit;
QCalendarWidget *calendarWidget;
private slots:
//-----------日历组件---------
void showTime();
void setData();
};
#endif // QTBUTTON_H
qtButton.cpp如下
#include "qtbutton.h"
//------------------------------
qtButton::qtButton(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
//-----------日历组件---------
label = new QLabel(this);
label->setText("choose data:");
label->setGeometry(QRect(50, 50, 100, 25));
lineEdit = new QLineEdit(this);
lineEdit->setGeometry(QRect(130, 50, 150, 22));
connect(lineEdit, SIGNAL(cursorPositionChanged(int, int)), this, SLOT(showTime()));
calendarWidget = new QCalendarWidget(this);
calendarWidget->setGeometry(20, 75, 350, 180);
calendarWidget->setHidden(true);
connect(calendarWidget, SIGNAL(clicked(QDate)), this, SLOT(setData));
}
qtButton::~qtButton()
{
}
void qtButton::showTime()
{
calendarWidget->setHidden(false);
}
void qtButton::setData()
{
QDate date = calendarWidget->selectedDate();
QString str = date.toString("yyyy-MM-dd");
lineEdit->setText(str);
calendarWidget->setHidden(true);
}
最后程序运行结果为:
相关文章推荐
- 图像缩放实现(Qt)
- QT枚举类型与字符串类型相互转换
- pyqt5 笔记(二)实现http请求发送
- 树莓派----03_安装QT5
- Qt之QTimer
- Qt之QTimer
- QT 编译动态DLL及使用
- Qt学习(五)-----自定义电子时钟
- Qt之QDesktopServices
- Qt之QDesktopServices
- 编译qt4.8.1时出现错误 error: 'union' tag used in naming 'struct _GMutex'
- Qt学习九:控件六:任务栏托盘菜单
- qt设置登录按钮点击后不可用变灰的立即执行
- Qt 学习之路 2(84):Repeater
- 5.60的QT移植到arm板(2)
- vs2005编译QT4.5版本
- QT:国内获得授权的QT镜像地址.
- Qt连接Oracle数据库常见问题
- QtQml 应用程序的性能考虑与建议(来自小V的翻译)
- Qt布局管理-堆栈窗体QStackedWidget类