获得更新日期:
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 } 只能选周一,写在这了图片前不好加文字
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 }
1 #include <QtGui/QMainWindow> 2 #include "ui_layout_demo.h" 3 #include <QDesktopWidget> 4 #include <QApplication> 5 #include <QRect> 6 #include "testwindow.h" 7 #include <QCalendarWidget> 8 #include <QMessageBox> 9 #include <QDate> 10 11 class layout_Demo : public QMainWindow 12 { 13 Q_OBJECT 14 15 public: 16 layout_Demo (QWidget *parent = 0, Qt::WFlags flags = 0); 17 ~layout_Demo(); 18 19 private slots: 20 // lyy : 2016/8/26 8:28:40 说明:日期更改时 21 void OnCalendarSelectChanged(); 22 // lyy : 2016/8/26 8:27:56 说明:天或年更改时 23 void OnCalendarYearMonthChanged (int iYear, int iMonth); 24 private: 25 Ui::layout_DemoClass ui; 26 testWindow *testDemo; 27 QDate oldDate; 28 };
http://pan.baidu.com/s/1eR2c6NC
时间: 2024-10-13 11:47:26