当前位置:网站首页>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
边栏推荐
- Relu function of activation function
- 第四章 为IM 启用填充对象之在NO INMEMORY表上指定INMEMORY列属性:示例(IM-4.4 第四部分)
- Intelligent multi line elastic cloud adds independent IP address. How to realize multi line function?
- Chapter 4: enable and disable im column storage for materialized view (IM 4.6)
- Tclerror: no display name and no $display environment variable
- C# F23. Stringsimilarity Library: String repeatability, text similarity, anti plagiarism
- Master slave replication configuration of MySQL
- Idea code formatting plug-in save actions
- Sofa weekly | excellent Committee of the year, contributor of this week, QA of this week
- 为什么hash%length==hash&(length-1)的前提是 length 是 2 的 n 次方
猜你喜欢

Share two practical shell scripts

软件测试基础DAY2-用例执行

Siri gave the most embarrassing social death moment of the year

Recommended programming AIDS: picture tool snipaste

Relu function of activation function

【Redis 系列】redis 学习十三,Redis 常问简单面试题

5个免费音频素材网站,建议收藏

c# 设置logo图标和快捷方式的图标

How do programmers finalize nucleic acid statistics with 130 lines of code

Force buckle - 70 climb stairs
随机推荐
Tensorflow common functions
画结果图推荐网址
Idea code quality specification plug-in sonarlint
SQL exercise (I)
oh-my-lotto
The fourth chapter is about enabling and disabling the im column storage of table space for im enabled filling objects (IM 4.5)
在 VSCode 中调试 Jest 的测试用例,VSCode调试Jest测试用例报错basedir=$(dirname “$(echo “$0“ | sed -e ‘s,\\,/,g‘)“)解决
软件测试对于减少程序BUG有多大帮助?
Debug Jest test cases in VSCode, debug Jest test cases in VSCode, middle note basedir=$(dirname "$" (echo "$0" sed -e -e, s, \ \, / "-e").
异步时钟亚稳态 的解决方案——多bit信号
IDEA 代码质量规范插件SonarLint
IMEU如何与IMCU相关联(IM 5.5)
Fastjson 2 is coming, the performance continues to improve, and it can fight for another ten years
Solution of asynchronous clock metastability -- multi bit signal
Chapter 5 optimizing queries using in memory expressions (IM 5.1)
Next. JS static data generation and server-side rendering
C# F23.StringSimilarity库 字符串重复度、文本相似度、防抄袭
What is a gateway
How to solve the computer system card?
Lesson 24 analysis of classical problems