《C++ GUI Qt 4 编程》 笔记(六)

第17章 提供在线帮助

工具提示

状态提示 显示在状态栏上

What’s This? 文本帮助

当处于what’s this模式下时(windows 标题栏问号按钮 或shift + f1)
单击窗体,将显示设置的帮助文本

QWhatsThis::createAction();

当用户按下F1键或单击Help菜单项时,应用程序主窗口会调用help()槽

QTextBrowser

QWidget::setAttribute(Qt::WA_DeleteOnClose)
// 通常模式对话框不允许和这个应用程序中的其他任何窗口进行交互
// 以下代码允许这种交互
QWidget::setAttribute(Qt::WA_GroupLeader)

textBrowser->documentTitle();

Qt Assitant库
.pro
CONFIG += assistant

第三部分 Qt高级

第19章 Unicode

QTextCodec::codecForLocale() 获得本地字符集

让应用程序感知翻译
1. tr()
2. 程序启动时,载入一个翻译文件.qm

另一种方式:

lupdate工具

不要含有变量

应该这样

QT_TRANSLATE_NOOP(“上下文”, “xxx”);

禁止const char* 到QString的隐含转换
在包含任意Qt头文件之前预先定义:
QT_NO_CAST_FROM_ASCII
或在.pro中
DEFINES += QT_NO_CAST_FROM_ASCII

QLocale 提供本地化的数字和日期以及时间格式

动态改变语言
只需重新加载翻译文件,然后重新设置需要翻译的文本

翻译应用程序:
1. 运行lupdate,从应用程序的源代码中提取所有用户可见的字符串
2. 使用Qt Linguist翻译应用程序
3. 运行lrelease,生成二进制的.qm文件,应用程序可以使用QTranslator加载这个文件

在.pro中加入需要支持的语言
当第一次运行lupdate时会创建这两个文件xml格式
ts – translate source
qm – Qt Message
TRANSLATIONS = spreadsheet_de.ts spreadSheet_fr.ts

lupdate -verbose spreadsheet.pro

CODECFORTR = …
QTextCodec::setCodecForTr()

lrelease -verbose spreadsheet.pro

第19章 自定义外观

三种方法重新定义Qt内置窗口部件的外观
1. 子类化窗口部件类
2. 子类化QStyle或者一个预定义的风格比如QWindowStyle,Qt通过这种方法为不同平台提供基于平台的外观
3. Qt样式表 受CSS启发

样式表作用于上层的当前激活的QStyle上,因为创建样式表不引入任何子类,所以它们适合对现有窗口部件做微小的定制。

例如:
想在应用程序中的所有QLineEdit中使用黄色作为背景色

QObject::setProperty()

QStyle
内置样式类:
QStyle
|- QCommonStyle
|  |-QWindowStyle
|  |-QCleanlookStyle
|  |-QMacStyle
|  |-QPlastiqueStyle
|  |-QWindowsXPStyle
|  |-QWindowsVistaStyle
|
|- QMotifStyle
|- QCDEStyle

class MyPushButton : public QWidget

QApplication::setStyle() // 设置整个应用程序的样式
QWidget::setStyle() // 为个别窗口部件设置样式

drawControl()函数被各种QStyle的子类重新实现,用于绘制窗口部件
第20章 三维绘图 OpenGL

1. 子类化QGLWidget
2. 实现几个虚函数
3. 连接QtOpenGL OpenGL库

.pro
QT += opengl

OpenGL QPainter结合
在paintEvent()函数绘制
1. 创建一个QPainter
2. 使用QPainter绘制背景
3. 保存OpenGL状态
4. 使用OpenGL操作绘制场景
5. 恢复OpenGL状态
6. 使用QPainter绘制前景
7. 销毁QPainter

QGLWidget::renderText()

使用帧缓存对象生成叠加
基本思路:
1. opengl渲染到纹理
2. 将纹理绘制到窗口
3. 将选择框绘制到窗口
假如只有窗口大小改变时才重新opengl渲染
这时,假如选择框的大小改变,而窗口大小没有改变时,则只需要绘制一张纹理和一个选择框,模型并不需要频繁渲染。

发布者

yjwx0017

C++软件工程师

《《C++ GUI Qt 4 编程》 笔记(六)》有24个想法

  1. It is really a nice and helpful piece of information. I am glad that you shared this useful information with us. Please keep us up to date like this. Thank you for sharing.

  2. Nice post. I find out some thing much harder on various blogs everyday. Most commonly it is stimulating to see content off their writers and exercise a little something from their store. I’d would prefer to apply certain while using content in this little weblog whether or not you do not mind. Natually I’ll provide a link on your own web weblog. Thank you sharing.

  3. I am still learning of your stuff, and i am attempting to achieve my objectives. I completely adore reading through all that is written in your website. Maintain the actual ideas arriving for long term ! Thanks !

  4. My husband and i ended up being very contented when Michael could finish up his basic research because of the precious recommendations he gained in your web pages. It is now and again perplexing to simply possibly be making a gift of tricks some others may have been making money from. We really consider we’ve got the blog owner to appreciate for that. Most of the explanations you’ve made, the straightforward web site navigation, the relationships you can make it easier to foster – it’s everything remarkable, and it is assisting our son and the family reckon that that issue is brilliant, which is certainly very essential. Thank you for everything! click here – alternative medicine

  5. excellent b/c [url=https://www.youtube.com/watch?v=k1oaz7n0ILk]Peruvian deep wave[/url] should not stain such as the swade textiles styles including the old nozzles you know and [url=http://adf.ly/6249830/banner/www.scamadviser.com/check-website/betterscooter.com]betterscooter.com[/url] still which usually locks indoors love them

  6. Inside my schooling Absolutely everyone brings in these individuals. Liked working out secured and also bought these people. At the shop My partner and i rarely were going to remove them. There’re as a result comforable and also smooth. They are simply so that value the total price. Top [url=http://adf.ly/6249830/banner/www.scamadviser.com/check-website/betterscooter.com]betterscooter.com[/url] That i have ever actually owned.

评论已关闭。