Qt之日历组件QCalendarWidget及日期、时间控件

本文展示了如何在Qt环境中创建日历控件和日期时间编辑框。通过QCalendarWidget实现日历选择,并关联QLineEdit显示选定日期。同时,利用QTimeEdit和QDateEdit展示系统当前时间与日期,允许用户进行选择。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

二、主要源码

2.1  日历控件(calendarWidget)

    //窗口尺寸
    this->resize(600,500);
    calendar_label = new QLabel(this);
    calendar_label->setText("选择日期");
    //标签以及编辑框位置
    calendar_label->setGeometry(QRect(100,70,100,25));
    calendar_Edit = new QLineEdit(this);
    calendar_Edit->setGeometry(QRect(180,70,150,25));
    //cursorPositionChanged触发的事件
    connect(calendar_Edit,SIGNAL(cursorPositionChanged(int,int)),this,SLOT(showTime()));
    //实例时间控件
    calendarWidget = new QCalendarWidget(this);
    //日历组件位置
    calendarWidget->setGeometry(25,98,450,280);
    //隐藏日历组件
    calendarWidget->setHidden(true);
    //时间控件点击事件
    connect(calendarWidget,SIGNAL(clicked(QDate)),this,SLOT(setDate()));
 
    //槽函数
    void Widget::showTime()
    {
         calendarWidget->setHidden(false);
    }
    
    void Widget::setDat
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值