获得更新日期:

1 //  ui.calendarWidget->setVerticalHeaderFormat (QCalendarWidget::ISOWeekNumbers);// lyy : 2016/8/26 8:54:14 说明:显示星期数
2     ui.calendarWidget->setVerticalHeaderFormat (QCalendarWidget::NoVerticalHeader);// lyy : 2016/8/26 8:56:07 说明:不显示星期数
1   void OnCalendarSelectChanged();
2         // lyy : 2016/8/26 8:27:56 说明:天或年更改时
3         void OnCalendarYearMonthChanged (int iYear, int iMonth);
1 connect (ui.calendarWidget,        SIGNAL (selectionChanged()),        this,        SLOT (OnCalendarSelectChanged()));
2     connect (ui.calendarWidget,        SIGNAL (currentPageChanged (int , int)),        this,        SLOT (OnCalendarYearMonthChanged (int, int)));
 1 QString AlarmPaper::strDateFromat = QObject::tr ("yyyy-MM-dd");
 2 void AlarmPaper::OnCalendarSelectChanged()
 3 {
 4     //const QChar* str=GlobalConstant::strDateFromat.data();
 5     mFlagTime = QDateTime (ui.calendarWidget->selectedDate());
 6     QString strTime = mFlagTime.toString (strDateFromat);
 7     ui.timeLabel->setText (strTime);
 8 }
 9 void AlarmPaper::OnCalendarYearMonthChanged (int iYear, int iMonth)
10 {
11     // lyy : 2016/9/20 10:57:18 说明:update the time mFlage
12     mFlagTime = QDateTime (QDate (iYear, iMonth, mFlagTime.date().day()));
13     QString strTime = mFlagTime.toString (strDateFromat);
14     ui.timeLabel->setText (strTime);
15 }


只能选周一,写在这了图片前不好加文字

Qt-QCalendarWidget只能选中周一及获取更新日期

 1 #include "layout_demo.h"
 2 
 3 layout_Demo::layout_Demo (QWidget *parent, Qt::WFlags flags)
 4     : QMainWindow (parent, flags)
 5 {
 6     ui.setupUi (this);
 7     /* QDesktopWidget* desktopWidget = QApplication::desktop();
 8     QRect clientRect = desktopWidget->availableGeometry();
 9     QRect applicationRect = desktopWidget->screenGeometry();
10     ui.centralWidget->setFixedSize (applicationRect.width(), applicationRect.height());*/
11     //testDemo = new testWindow (ui.mainWindow_widget);
12     // testDemo->show();
13     //
14     //
15     connect (ui.calendarWidget,        SIGNAL (selectionChanged()),        this,        SLOT (OnCalendarSelectChanged()));
16     connect (ui.calendarWidget,        SIGNAL (currentPageChanged (int , int)),        this,        SLOT (OnCalendarYearMonthChanged (int, int)));
17     ui.calendarWidget->setSelectionMode (QCalendarWidget::SelectionMode (1));
18     // ui.calendarWidget->setFirstDayOfWeek (Qt::DayOfWeek::Friday);
19     oldDate = ui.calendarWidget->selectedDate();
20     // QDate firstFriday (ui.calendarWidget->yearShown(), ui.calendarWidget->monthShown(), 1);
21     //  QDate endRange = firstFriday.addMonths (1);
22     // ui.calendarWidget->setDateRange (firstFriday, endRange);
23     //
24 }
25 
26 void layout_Demo::OnCalendarYearMonthChanged (int iYear, int iMonth)
27 {
28     if (oldDate.day() == ui.calendarWidget->selectedDate().day())
29     {
30         QDate firstFriday (ui.calendarWidget->yearShown(), ui.calendarWidget->monthShown(), 1);
31         // oldDate = ui.calendarWidget->selectedDate();
32         oldDate = firstFriday;
33     }
34     
35     // lyy : 2016/9/12 11:11:49 说明: 判断是不是手动还是自动
36 }
37 void layout_Demo::OnCalendarSelectChanged()
38 {
39     //const QChar* str=GlobalConstant::strDateFromat.data();
40     QString strTime = ui.calendarWidget->selectedDate().toString ("ddd");
41     // QDate firstFriday (ui.calendarWidget->yearShown(), ui.calendarWidget->monthShown(), 1);
42     
43     if (ui.calendarWidget->selectedDate().dayOfWeek() == 1 && oldDate.month() == ui.calendarWidget->monthShown())
44     {
45         // QMessageBox::information (this, "test", "d");
46         oldDate = ui.calendarWidget->selectedDate();
47     }
48     
49     else
50     {
51         ui.calendarWidget->setSelectedDate (oldDate);
52     }
53     
54     //ui.timeLabel->setText (strTime);
55     //
56 }
57 layout_Demo::~layout_Demo()
58 {
59 }
View Code

相关文章:

  • 2022-12-23
  • 2022-01-06
  • 2021-11-11
  • 2021-08-14
  • 2022-12-23
  • 2022-12-23
  • 2021-07-30
  • 2022-12-23
猜你喜欢
  • 2021-11-27
  • 2021-06-20
  • 2021-06-30
  • 2022-03-04
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案