def initUI(self): cal = QCalendarWidget(self) cal.setGridVisible(True) cal.setVerticalHeaderFormat( QCalendarWidget.VerticalHeaderFormat( QCalendarWidget.NoVerticalHeader)) cal.clicked[QDate].connect(self.showDate) # 한국 공휴일 캘린더 객체 생성 후 올해 기준으로 휴일을 3년간 Q캘린터에 표시 wcal = SouthKorea() date = QDate.currentDate() # 해당 연도의 공휴일을 리스트로 반환 # print(wcal.holidays(date.year())) # 공휴일 표시 서식 설정 fm = QTextCharFormat() fm.setForeground(Qt.red) # fm.setBackground(Qt.yellow) # 올해 기준 전년, 올해, 다음해까지 공휴일 표시 for one in wcal.holidays(date.year() - 1): print(one[0]) cal.setDateTextFormat(one[0], fm) for one in wcal.holidays(date.year()): print(one[0]) cal.setDateTextFormat(one[0], fm) for one in wcal.holidays(date.year() + 1): print(one[0]) cal.setDateTextFormat(one[0], fm) self.lbl = QLabel(self) date = cal.selectedDate() self.lbl.setText(date.toString()) self.lblmsg = QLabel(self) self.lblmsg.setText("강의 일정 계산") self.showDate(date) vbox = QVBoxLayout() vbox.addWidget(cal) vbox.addWidget(self.lbl) vbox.addWidget(self.lblmsg) self.setLayout(vbox) self.setWindowTitle('종강일 계산기') self.setGeometry(300, 300, 300, 300) self.show()
def verticalHeaderChanged(self, index): self.calendar.setVerticalHeaderFormat( QCalendarWidget.VerticalHeaderFormat( self.verticalHeaderCombo.itemData(index)))