简体   繁体   中英

QCalendarWidget: how to set specific day when changing the month?

I created a QCalendarWidget in my Gui. By default, if you change the month in the calendar NavigationBar, the day is not set to anything (ie: the user have to select it manually otherwise no day is set). I am trying to connect a signal that each time I change the month (ie: from June to May) the day is set from the current day to the first of that month (ie: from 12 to 1).

I already built the "connect function" using sinal: currentPageChanged(int, int) which is working fine. then, inside this slot, I am trying to update the day to become the 1st which is something I could do as there is no setDay() function !!

so, how can I set the 1st day of the selected month each time I change the current month in QCalendarWidget ?

try inside your slot (assuming your QCalendarWidget is named calendar):

QDate date = calendar.selectedDate();
date.setDate(date.year(),date.month(),1);
calendar.setSelectedDate(date);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM