【独家】QT实现日历显示

2022-12-12 10:21:12 来源:51CTO博客


(资料图片仅供参考)

void Window::localeChanged(int index){    const QLocale newLocale(localeCombo->itemData(index).toLocale());    calendar->setLocale(newLocale);    int newLocaleFirstDayIndex = firstDayCombo->findData(newLocale.firstDayOfWeek());    firstDayCombo->setCurrentIndex(newLocaleFirstDayIndex);}void Window::firstDayChanged(int index){    calendar->setFirstDayOfWeek(Qt::DayOfWeek(                                firstDayCombo->itemData(index).toInt()));}void Window::selectionModeChanged(int index){    calendar->setSelectionMode(QCalendarWidget::SelectionMode(                               selectionModeCombo->itemData(index).toInt()));}void Window::horizontalHeaderChanged(int index){    calendar->setHorizontalHeaderFormat(QCalendarWidget::HorizontalHeaderFormat(        horizontalHeaderCombo->itemData(index).toInt()));}void Window::verticalHeaderChanged(int index){    calendar->setVerticalHeaderFormat(QCalendarWidget::VerticalHeaderFormat(        verticalHeaderCombo->itemData(index).toInt()));}void Window::selectedDateChanged(){    currentDateEdit->setDate(calendar->selectedDate());}void Window::minimumDateChanged(const QDate &date){    calendar->setMinimumDate(date);    maximumDateEdit->setDate(calendar->maximumDate());}void Window::maximumDateChanged(const QDate &date){    calendar->setMaximumDate(date);    minimumDateEdit->setDate(calendar->minimumDate());}void Window::weekdayFormatChanged(){    QTextCharFormat format;    format.setForeground(qvariant_cast(        weekdayColorCombo->itemData(weekdayColorCombo->currentIndex())));    calendar->setWeekdayTextFormat(Qt::Monday, format);    calendar->setWeekdayTextFormat(Qt::Tuesday, format);    calendar->setWeekdayTextFormat(Qt::Wednesday, format);    calendar->setWeekdayTextFormat(Qt::Thursday, format);    calendar->setWeekdayTextFormat(Qt::Friday, format);}void Window::weekendFormatChanged(){    QTextCharFormat format;    format.setForeground(qvariant_cast(        weekendColorCombo->itemData(weekendColorCombo->currentIndex())));    calendar->setWeekdayTextFormat(Qt::Saturday, format);    calendar->setWeekdayTextFormat(Qt::Sunday, format);}void Window::reformatHeaders(){    QString text = headerTextFormatCombo->currentText();    QTextCharFormat format;    if (text == tr("Bold")) {        format.setFontWeight(QFont::Bold);    } else if (text == tr("Italic")) {        format.setFontItalic(true);    } else if (text == tr("Green")) {        format.setForeground(Qt::green);    }    calendar->setHeaderTextFormat(format);}

标签: setHeaderTextFormat horizontalHeaderChanged

上一篇:资讯:异构混排在vivo互联网的技术实践
下一篇:win7将PowerShell升级到4.0