当前位置:网站首页>关于非虚函数的假派生
关于非虚函数的假派生
2022-07-06 03:21:00 【氺月洞天】
以QPushButton的initStyleOption为例
先看源码,该函数为保护函数
void QPushButton::initStyleOption(QStyleOptionButton *option) const
{
if (!option)
return;
Q_D(const QPushButton);
option->initFrom(this);
option->features = QStyleOptionButton::None;
if (d->flat)
option->features |= QStyleOptionButton::Flat;
#if QT_CONFIG(menu)
if (d->menu)
option->features |= QStyleOptionButton::HasMenu;
#endif
if (autoDefault())
option->features |= QStyleOptionButton::AutoDefaultButton;
if (d->defaultButton)
option->features |= QStyleOptionButton::DefaultButton;
if (d->down || d->menuOpen)
option->state |= QStyle::State_Sunken;
if (d->checked)
option->state |= QStyle::State_On;
if (!d->flat && !d->down)
option->state |= QStyle::State_Raised;
option->text = d->text;
option->icon = d->icon;
option->iconSize = iconSize();
}
重写该函数:
头文件
#ifndef XX_H
#define XX_H
#include <QtWidgets>
class PushButton : public QPushButton
{
public:
PushButton(QWidget *parent);
~PushButton();
void paintEvent(QPaintEvent *) override;
};
#endif // XX_H
源文件
#include "xx.h"
#include "private/qpushbutton_p.h"
PushButton::PushButton(QWidget *parent)
: QPushButton(parent)
{
}
PushButton::~PushButton()
{
}
void PushButton::paintEvent(QPaintEvent *)
{
QStylePainter p(this);
QStyleOptionButton option;
QPushButton::initStyleOption(&option);
p.drawControl(QStyle::CE_PushButton, option);
}
void QPushButton::initStyleOption(QStyleOptionButton *option) const
{
qInfo() << __LINE__;
if (!option)
return;
Q_D(const QPushButton);
option->initFrom(this);
option->features = QStyleOptionButton::None;
if (d->flat)
option->features |= QStyleOptionButton::Flat;
#if QT_CONFIG(menu)
if (d->menu)
option->features |= QStyleOptionButton::HasMenu;
#endif
if (autoDefault())
option->features |= QStyleOptionButton::AutoDefaultButton;
if (d->defaultButton)
option->features |= QStyleOptionButton::DefaultButton;
if (d->down || d->menuOpen)
option->state |= QStyle::State_Sunken;
if (d->checked)
option->state |= QStyle::State_On;
if (!d->flat && !d->down)
option->state |= QStyle::State_Raised;
option->text = d->text;
option->icon = d->icon;
option->iconSize = iconSize();
}
边栏推荐
- JS音乐在线播放插件vsPlayAudio.js
- Web security SQL injection vulnerability (1)
- MySQL Server层四个日志
- [slam] lidar camera external parameter calibration (Hong Kong University marslab) does not need a QR code calibration board
- ASU & OSU | model based regularized off-line meta reinforcement learning
- OCR文字識別方法綜述
- [pointer training - eight questions]
- Mysqldump data backup
- JS regular filtering and adding image prefixes in rich text
- 真机无法访问虚拟机的靶场,真机无法ping通虚拟机
猜你喜欢
JS音乐在线播放插件vsPlayAudio.js
Image super-resolution using deep convolutional networks(SRCNN)解读与实现
Edcircles: a real time circle detector with a false detection control translation
深入刨析的指针(题解)
Jenkins basic knowledge ----- detailed explanation of 03pipeline code
Pytorch load data
SAP ALV color code corresponding color (finishing)
Pointer for in-depth analysis (problem solution)
mysqldump数据备份
遥感图像超分辨重建综述
随机推荐
电机控制反Park变换和反Clarke变换公式推导
Leetcode problem solving -- 99 Restore binary search tree
SAP ALV color code corresponding color (finishing)
3857墨卡托坐标系转换为4326 (WGS84)经纬度坐标
Some problem records of AGP gradle
【Rust 笔记】18-宏
给新人工程师组员的建议
蓝色样式商城网站页脚代码
Getting started with applet cloud development - getting user search content
继承day01
jsscript
StrError & PERROR use yyds dry inventory
Résumé des méthodes de reconnaissance des caractères ocr
JS音乐在线播放插件vsPlayAudio.js
js凡客banner轮播图js特效
暑期刷题-Day3
如何做好功能测试
Add one to non negative integers in the array
出现Permission denied的解决办法(750权限谨慎使用)
【概念】Web 基础概念认知