当前位置:网站首页>Qt绘制文字
Qt绘制文字
2022-04-23 12:10:00 【MechMaster】
Qt绘制文字
void Widget::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
QRectF rect(10.0,10.0,380.0,280.0);
painter.setPen(Qt::red);
painter.drawRect(rect);
painter.setPen(Qt::blue);
//参数:绘制文字所在的矩形、文字在矩形中的对齐方式、绘制的文字\n能实现换行
painter.drawText(rect,Qt::AlignHCenter,tr("AlignHCenter"));
painter.drawText(rect,Qt::AlignLeft,tr("AlignLeft"));
painter.drawText(rect,Qt::AlignRight,tr("AlignRight"));
painter.drawText(rect,Qt::AlignHCenter,tr("AlignHCenter"));
painter.drawText(rect,Qt::AlignBottom,tr("AlignBottom"));
painter.drawText(rect,Qt::AlignCenter,tr("AlignCenter"));
painter.drawText(rect,Qt::AlignBottom | Qt::AlignBottom,tr("AlignBottom/AlignBottom"));
//参数:字体的family属性、大小、是否是用粗体、是否使用斜体
QFont font("宋体",15,QFont::Bold,true);
//设置下划线
font.setOverline(true);
//设置字母大小写
font.setCapitalization(QFont::SmallCaps);
//设置字符间的间距
font.setLetterSpacing(QFont::AbsoluteSpacing,10);
//使用字体
painter.setFont(font);
painter.setPen(Qt::red);
painter.drawText(120,80,tr("Hello world!"));
painter.translate(100,100);
painter.rotate(90);
painter.drawText(0,0,tr("Hello Qt!"));
}
版权声明
本文为[MechMaster]所创,转载请带上原文链接,感谢
https://liuhui.blog.csdn.net/article/details/124264225
边栏推荐
- 抓包整理————tcp 协议[八]
- Idea setting copyright information
- 运行报错:找不到或无法加载主类 com.xxx.Application
- Intelligent multi line elastic cloud adds independent IP address. How to realize multi line function?
- Tips for installing MySQL service in windows11: Install / Remove of the Service denied
- 【Redis 系列】redis 学习十三,Redis 常问简单面试题
- IM表达式如何工作(5.3)
- 《通用数据保护条例》(GDPR)系列解读三:欧洲子公司如何向国内母公司回传数据?
- Solution of asynchronous clock metastability -- multi bit signal
- Xinwangda announced that the price of battery products had been increased, and the investment of "weixiaoli" exceeded 1 billion
猜你喜欢
Fastjson 2 is coming, the performance continues to improve, and it can fight for another ten years
2022 love analysis · panoramic report of industrial Internet manufacturers
Idea code formatting plug-in save actions
Idea database navigator plug-in
IDEA 中 .properties文件的中文显示乱码问题的解决办法
Force buckle - 1137 Nth teponacci number
Debug Jest test cases in VSCode, debug Jest test cases in VSCode, middle note basedir=$(dirname "$" (echo "$0" sed -e -e, s, \ \, / "-e").
PSCP 基本使用
After a circle, I sorted out this set of interview questions..
激活函数之阶跃函数
随机推荐
IDEA 数据库插件Database Navigator 插件
数据库如何填充IM表达式(IM 5.4)
Design and practice of the smallest short website system in the whole network
WIN10 启动后花屏
Recommended programming AIDS: picture tool snipaste
运行报错:找不到或无法加载主类 com.xxx.Application
程序员如何用130行代码敲定核酸统计
ImportError: libX11. so. 6: cannot open shared object file: No such file or directory
亿级流量架构,服务器如何扩容?写得太好了!
The fourth chapter is about enabling and disabling the im column storage of table space for im enabled filling objects (IM 4.5)
IM 体系结构:CPU架构:SIMD向量处理(IM-2.3)
Solution of asynchronous clock metastability -- multi bit signal
Why is there a wrapper class? By the way, how to convert basic data types, wrapper classes and string classes?
5个免费音频素材网站,建议收藏
Share two practical shell scripts
After a circle, I sorted out this set of interview questions..
数组---
IDEA设置版权信息
Worder font page font comparison table
Fastjson 2 is coming, the performance continues to improve, and it can fight for another ten years