当前位置:网站首页>Qt development experience tips 231-235
Qt development experience tips 231-235
2022-08-06 03:33:00 【feiyangqingyun】
- 关于c++中继承多态virtual和override的几点总结.
- 子类可以直接使用基类中的protected下的变量和函数.
- 基类函数没加virtual,子类有相同函数,实现的是覆盖.用基类指针调用时,调用到的是基类的函数;用子类指针调用时,调用到的是子类的函数.
- 基类函数加了virtual时,实现的时重写.用基类指针或子类指针调用时,调用到的都是子类的函数.
- 函数加上override,强制要求子类相同函数需要是虚函数,而且必须重新实现,否则会编译报错.
- 子类的virtual可加可不加,建议加override不加virtual.
- 基类中的纯虚函数(virtual void play() = 0;)在基类中无需在cpp中实现,但是必须在子类实现,否则编译报错.
- 继承多态最大的好处就是提炼共性,将通用的变量和方法信号等,全部放在基类,子类负责实现自己需要的特殊的部分即可.
- 关于 QTableView、QTableWidget 悬停整行选中效果,网上大多数都是针对 QTableWidget 的实现,针对 QTableView 的也都是通过委托或者重新painter实现.
- 前提:设置选中单元格自动选中整行,tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
- 安装事件过滤器,识别到当前坐标处的数据模型,然后设置当前模型为鼠标悬停处的模型即可.这个取巧的办法可以节省大量的工作.
- 无论 QTableView、QTableWidget 都用此方法都可以.
- Qt中如何避免和第三方的signals、slots等关键字冲突.
- 第一步:在pro中加上 CONFIG += no_keywords .
- 第二步:项目中之前所有的 signals 改成 Q_SIGNALS,slots 改成 Q_SLOTS 等.
- 第三步:彻底重新编译项目,这样就关键字不冲突了.
- pro中区分不同的操作系统及硬件平台.
win32 {
}
unix {
}
//Qt5可以直接用 linux{} Qt4切记需要用 unix:!maxc{}
unix:!maxc{
}
linux {
}
maxc {
}
android {
}
wasm {
}
//表示64位平台
contains(QT_ARCH, x86_64) {
}
//表示arm平台
contains(QT_ARCH, arm) || contains(QT_ARCH, arm64) {
}
//万能办法直接切换到套件打印下 QT_ARCH 看下什么字符
message($$QT_ARCH)
- 在显示视频画面位置的时候,一般会有三种机制作为参考,自动调整(画面尺寸大于显示控件尺寸则等比例缩放,否则原图显示)、等比例缩放、拉伸填充.Qt中图片类QImage都提供了缩放策略的参数设置,比如Qt::KeepAspectRatio表示等比例缩放,但很多时候我们需要的是设置控件的大小,其实QSize类就提供了对应的方法scale专门解决这个问题,这个方法很容易被忽视.
//传入图片尺寸和窗体区域及边框大小返回居中区域
static QRect getCenterRect(const QSize &imageSize, const QRect &widgetRect, int borderWidth = 2, bool alwaysScale = true)
{
QSize newSize = imageSize;
QSize widgetSize = widgetRect.size() - QSize(borderWidth * 2, borderWidth * 2);
//alwaysScale = false 表示只有尺寸超过窗体尺寸才缩放否则就原图尺寸
if (alwaysScale) {
newSize.scale(widgetSize, Qt::KeepAspectRatio);
} else if (newSize.width() > widgetSize.width() || newSize.height() > widgetSize.height()) {
newSize.scale(widgetSize, Qt::KeepAspectRatio);
}
int x = widgetRect.center().x() - newSize.width() / 2;
int y = widgetRect.center().y() - newSize.height() / 2;
return QRect(x, y, newSize.width(), newSize.height());
}
//传入图片尺寸和窗体尺寸及缩放策略返回合适尺寸的图片
static void getScaledImage(QImage &image, const QSize &widgetSize, bool alwaysScale = false, bool fast = true)
{
//alwaysScale = false 表示只有尺寸超过窗体尺寸才缩放否则就原图尺寸
if (alwaysScale) {
image = image.scaled(widgetSize, Qt::KeepAspectRatio, fast ? Qt::FastTransformation : Qt::SmoothTransformation);
} else if (image.width() > widgetSize.width() || image.height() > widgetSize.height()) {
image = image.scaled(widgetSize, Qt::KeepAspectRatio, fast ? Qt::FastTransformation : Qt::SmoothTransformation);
}
}
国内站点:https://gitee.com/feiyangqingyun
国际站点:https://github.com/feiyangqingyun
边栏推荐
- 电赛电源类题型之问
- leetcode 15. 三数之和
- Deep Learning Course2 Week 2 Hyperparameter tuning, Batch Normalization, Programming Frameworks exercises
- 2022 Alibaba Cloud server configuration selection strategy
- LabVIEW 应用程序视窗始终置于顶层
- Smart Contract Security - Random Numbers
- The Google account was suspended for three months and reactivated, and the Google account was suspended for three months and reactivated. Is the conversion goal valid?
- xctf攻防世界 Web高手进阶区 easytornado
- xctf攻防世界 Web高手进阶区 command_execution
- Liunx常用命令
猜你喜欢

学习MySQL的第二天:SQL(基础篇)

What is an Egg. The js, it have what features, installation of an Egg framework, definition of routing, what's Controller is the Controller, CORS configuration, the json configuration, a get request,

经典sql例子

89.(cesium之家)cesium聚合图(自定义图片)

FluentValidation

xctf attack and defense world Web master advanced area easytornado

造自己的芯,让谷歌买单!谷歌再度开源 180nm 工艺的芯片

物联网协议概述

电赛电源类题型之问

【Untitled】
随机推荐
2022年京东新百货七夕礼遇季活动有什么亮点?
Wang Qi, Secretary of the Party Committee and President of Shanghai Pudong Development Bank Changsha Branch, and Jiang Junwen, President of Huarong Xiangjiang Bank, visited Kylin Principal for investi
入坑机器学习:三,非监督学习
Qt开发经验小技巧231-235
如果一个国家市场效果特别好,我们如何加大这个国家的投放比例。
实心轮胎的优缺点
ctf (finalrec)
【无标题】
网络安全辅助工具:免费MD5解密网站
造自己的芯,让谷歌买单!谷歌再度开源 180nm 工艺的芯片
Entering the pit of machine learning: 2. Supervised learning
If a country's market effect is particularly good, how can we increase the proportion of this country's investment?
深度学习Course2第二周Hyperparameter tuning, Batch Normalization, Programming Frameworks习题整理
个推数据智能技术实践 | 教你打造数据质量心电图,智能检测数据“心跳”异常
【无标题】目录测试
Deep Learning Course2 Week 2 Hyperparameter tuning, Batch Normalization, Programming Frameworks exercises
C 学生管理系统 打印/修改指定位置信息
Internet Security Aid: Free MD5 Decryption Website
慎用BeanUtils,性能真的拉跨!
2022年阿里云服务器配置选取攻略