当前位置:网站首页>QSS, qdateedit, qcalendarwidget custom settings
QSS, qdateedit, qcalendarwidget custom settings
2022-04-23 05:28:00 【Oriental forgetfulness】


The style of the date editor only needs to be set qss that will do .
m_dateedit->setStyleSheet("QDateEdit#MDateEdit{background:#4455ff;color:white;selection-color:yellow;"
"font-size:24px;"
"border-radius:5px;"
"border:2px solid #4455ff;}"
"QDateEdit#MDateEdit:hover{border:2px solid black;}"
"QDateEdit#MDateEdit:focus{border:2px solid gray;}"
"QDateEdit#MDateEdit::drop-down{width:30px;background:#A055ffff;border-radius:2px;}"
"QDateEdit#MDateEdit::down-arrow{image:url(/home/yjd/Desktop/ file / menu - suspension .png)}")
The calendar display can also be through qss Set the style , But you can't change the position of the button inside , Text , Icon .
m_dateedit->setStyleSheet("QDateEdit#MDateEdit{background:#4455ff;color:white;selection-color:yellow;"
"font-size:24px;"
"border-radius:5px;"
"border:2px solid #4455ff;}"
"QDateEdit#MDateEdit:hover{border:2px solid black;}"
"QDateEdit#MDateEdit:focus{border:2px solid gray;}"
"QDateEdit#MDateEdit::drop-down{width:30px;background:#A055ffff;border-radius:2px;}"
"QDateEdit#MDateEdit::down-arrow{image:url(/home/yjd/Desktop/ file / menu - suspension .png)}"
"QCalendarWidget#MCalendarwidget{border-radius:8px;}"
"QCalendarWidget QTableView{alternate-background-color: rgb(128, 128, 128);"
"background-color: #AFAFAE;"
"color:white;"
"selection-background-color:#dddddd;"
"selection-color:yellow;"
"border-left: 2px solid #AFAFAE;"
"border-right: 2px solid #AFAFAE;"
"border-bottom: 2px solid #AFAFAE;"
"border-bottom-left-radius:8px;border-bottom-right-radius:8px;}");
If you want to change the position of the internal button , At this time, you need to understand QCalendarWidget Source code , There are two main functions :
QCalendarWidget::QCalendarWidget(QWidget *parent)
: QWidget(*new QCalendarWidgetPrivate, parent, 0)
{
Q_D(QCalendarWidget);
setAutoFillBackground(true);
setBackgroundRole(QPalette::Window);
QVBoxLayout *layoutV = new QVBoxLayout(this);
layoutV->setMargin(0);
d->m_model = new QCalendarModel(this);
QTextCharFormat fmt;
fmt.setForeground(QBrush(Qt::red));
d->m_model->m_dayFormats.insert(Qt::Saturday, fmt);
d->m_model->m_dayFormats.insert(Qt::Sunday, fmt);
d->m_view = new QCalendarView(this);
d->m_view->setObjectName(QLatin1String("qt_calendar_calendarview"));
d->m_view->setModel(d->m_model);
d->m_model->setView(d->m_view);
d->m_view->setSelectionBehavior(QAbstractItemView::SelectItems);
d->m_view->setSelectionMode(QAbstractItemView::SingleSelection);
d->m_view->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
d->m_view->horizontalHeader()->setSectionsClickable(false);
d->m_view->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
d->m_view->verticalHeader()->setSectionsClickable(false);
d->m_selection = d->m_view->selectionModel();
d->createNavigationBar(this);
d->m_view->setFrameStyle(QFrame::NoFrame);
d->m_delegate = new QCalendarDelegate(d, this);
d->m_view->setItemDelegate(d->m_delegate);
d->update();
d->updateNavigationBar();
setFocusPolicy(Qt::StrongFocus);
setFocusProxy(d->m_view);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
connect(d->m_view, SIGNAL(showDate(QDate)),
this, SLOT(_q_slotShowDate(QDate)));
connect(d->m_view, SIGNAL(changeDate(QDate,bool)),
this, SLOT(_q_slotChangeDate(QDate,bool)));
connect(d->m_view, SIGNAL(clicked(QDate)),
this, SIGNAL(clicked(QDate)));
connect(d->m_view, SIGNAL(editingFinished()),
this, SLOT(_q_editingFinished()));
connect(d->prevMonth, SIGNAL(clicked(bool)),
this, SLOT(_q_prevMonthClicked()));
connect(d->nextMonth, SIGNAL(clicked(bool)),
this, SLOT(_q_nextMonthClicked()));
connect(d->yearButton, SIGNAL(clicked(bool)),
this, SLOT(_q_yearClicked()));
connect(d->monthMenu, SIGNAL(triggered(QAction*)),
this, SLOT(_q_monthChanged(QAction*)));
connect(d->yearEdit, SIGNAL(editingFinished()),
this, SLOT(_q_yearEditingFinished()));
layoutV->setMargin(0);
layoutV->setSpacing(0);
layoutV->addWidget(d->navBarBackground);
layoutV->addWidget(d->m_view);
d->m_navigator = new QCalendarTextNavigator(this);
setDateEditEnabled(true);
}
void QCalendarWidgetPrivate::createNavigationBar(QWidget *widget)
{
Q_Q(QCalendarWidget);
navBarBackground = new QWidget(widget);
navBarBackground->setObjectName(QLatin1String("qt_calendar_navigationbar"));
navBarBackground->setAutoFillBackground(true);
navBarBackground->setBackgroundRole(QPalette::Highlight);
prevMonth = new QPrevNextCalButton(navBarBackground);
nextMonth = new QPrevNextCalButton(navBarBackground);
prevMonth->setAutoRaise(true);
nextMonth->setAutoRaise(true);
prevMonth->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
nextMonth->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
nextMonth->setAutoRaise(true);
updateButtonIcons();
prevMonth->setAutoRepeat(true);
nextMonth->setAutoRepeat(true);
monthButton = new QCalToolButton(navBarBackground);
monthButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
monthButton->setAutoRaise(true);
monthButton->setPopupMode(QToolButton::InstantPopup);
monthMenu = new QMenu(monthButton);
for (int i = 1; i <= 12; i++) {
QString monthName(q->locale().standaloneMonthName(i, QLocale::LongFormat));
QAction *act = monthMenu->addAction(monthName);
act->setData(i);
monthToAction[i] = act;
}
monthButton->setMenu(monthMenu);
yearButton = new QCalToolButton(navBarBackground);
yearButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
yearButton->setAutoRaise(true);
yearEdit = new QSpinBox(navBarBackground);
QFont font = q->font();
font.setBold(true);
monthButton->setFont(font);
yearButton->setFont(font);
yearEdit->setFrame(false);
yearEdit->setMinimum(m_model->m_minimumDate.year());
yearEdit->setMaximum(m_model->m_maximumDate.year());
yearEdit->hide();
spaceHolder = new QSpacerItem(0,0);
QHBoxLayout *headerLayout = new QHBoxLayout;
headerLayout->setMargin(0);
headerLayout->setSpacing(0);
headerLayout->addWidget(prevMonth);
headerLayout->insertStretch(headerLayout->count());
headerLayout->addWidget(monthButton);
headerLayout->addItem(spaceHolder);
headerLayout->addWidget(yearButton);
headerLayout->insertStretch(headerLayout->count());
headerLayout->addWidget(nextMonth);
navBarBackground->setLayout(headerLayout);
yearEdit->setFocusPolicy(Qt::StrongFocus);
prevMonth->setFocusPolicy(Qt::NoFocus);
nextMonth->setFocusPolicy(Qt::NoFocus);
yearButton->setFocusPolicy(Qt::NoFocus);
monthButton->setFocusPolicy(Qt::NoFocus);
//set names for the header controls.
prevMonth->setObjectName(QLatin1String("qt_calendar_prevmonth"));
nextMonth->setObjectName(QLatin1String("qt_calendar_nextmonth"));
monthButton->setObjectName(QLatin1String("qt_calendar_monthbutton"));
yearButton->setObjectName(QLatin1String("qt_calendar_yearbutton"));
yearEdit->setObjectName(QLatin1String("qt_calendar_yearedit"));
updateMonthMenu();
showMonth(m_model->m_date.year(), m_model->m_date.month());
}
Through this, you can find QCalendarWidget Mode of construction , And you can also find the corresponding button ObjectName, Through this ObjectName You can take out the corresponding button to operate , as follows :
QToolButton *prevBtn = m_calendarwidget->findChild<QToolButton*>(QLatin1String("qt_calendar_prevmonth"));
QToolButton *nextBtn = m_calendarwidget->findChild<QToolButton*>(QLatin1String("qt_calendar_nextmonth"));
prevBtn->setIcon(QIcon());
nextBtn->setIcon(QIcon());
prevBtn->setText(" The previous page ");
nextBtn->setText(" The next page ");
This is to get the previous page respectively 、 Buttons on the next page , Then configure this button .
Source code download address
版权声明
本文为[Oriental forgetfulness]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220543307381.html
边栏推荐
- 如果我是pm之 演出电影vr购票展示
- Membarrier (personal learning and understanding)
- [no title] Click the classification jump page to display the details
- Domain driven model DDD (III) -- using saga to manage transactions
- what is wifi6?
- open3d材质设置参数分析
- Necessity of selenium preloading cookies
- Low code and no code considerations
- 弘玑微课堂 | Cyclone RPA之“灵活的数字员工”执行器
- Top 25 Devops tools in 2021 (Part 2)
猜你喜欢

what is wifi6?

The 2021 IT industry project management survey report was released!

Domain driven model DDD (III) -- using saga to manage transactions

Three methods of list rendering

2021-11-01

Qingdao agile tour, coming!

Project manager's thinking mode worth trying: project success equation

双击.jar包无法运行解决方法

Top 25 Devops tools in 2021 (Part 2)

MFC implementation resources are implemented separately by DLL
随机推荐
TSlint注释忽略错误和RESTful理解
Create a tabbar component under the components folder, which is public
CORS and proxy (づ  ̄ 3  ̄) in egg ~ the process of stepping on the pit and filling the pit ~ tot~
如果我是pm之 演出电影vr购票展示
狼叔来找翻译人员了--plato--持续翻译中.....
Kanban Quick Start Guide
可執行程序執行流程
Camera imaging + homography transformation + camera calibration + stereo correction
To understand Devops, you must read these ten books!
Multiple mainstream SQL queries only take the latest one of the data
Why can't V-IF and V-for be used together
(十一)vscode代码格式化配置
Uniapp hot update with progress bar
Watch depth monitoring mode
Wbpack configuring production development environment
C# ,类库
Devops life cycle, all you want to know is here!
d. TS --- for more detailed knowledge, please refer to the introduction on the official website (chapter of declaration document)
Arithmetic and logical operations
Traversal array, object parent-child communication props / $emit