消息框按钮文字汉化

This commit is contained in:
Irony 2019-07-10 14:10:51 +08:00
parent 49b0fb189a
commit ac9fdaf769
5 changed files with 127 additions and 1 deletions

View file

@ -32,6 +32,7 @@ encoding//QListView/CustomWidgetSortItem.py=utf-8
encoding//QListView/SortItemByRole.py=utf-8 encoding//QListView/SortItemByRole.py=utf-8
encoding//QListWidget/FoldWidget.py=utf-8 encoding//QListWidget/FoldWidget.py=utf-8
encoding//QListWidget/SignalsExample.py=utf-8 encoding//QListWidget/SignalsExample.py=utf-8
encoding//QMessageBox/ChineseText.py=utf-8
encoding//QMessageBox/CustomColorIcon.py=utf-8 encoding//QMessageBox/CustomColorIcon.py=utf-8
encoding//QProgressBar/Lib/WaterRippleProgressBar.py=utf-8 encoding//QProgressBar/Lib/WaterRippleProgressBar.py=utf-8
encoding//QProgressBar/MetroCircleProgress.py=utf-8 encoding//QProgressBar/MetroCircleProgress.py=utf-8

114
QMessageBox/ChineseText.py Normal file
View file

@ -0,0 +1,114 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on 2019年7月10日
@author: Irony
@site: https://pyqt5.com https://github.com/892768447
@email: 892768447@qq.com
@file: ChineseText
@description: 修改消息对话框文字汉化
"""
import sys
from PyQt5.QtWidgets import QApplication, QMessageBox
__Author__ = 'Irony'
__Copyright__ = 'Copyright (c) 2019 Irony'
__Version__ = 1.0
TextStyle = """
QMessageBox QPushButton[text="OK"] {
qproperty-text: "好的";
}
QMessageBox QPushButton[text="Open"] {
qproperty-text: "打开";
}
QMessageBox QPushButton[text="Save"] {
qproperty-text: "保存";
}
QMessageBox QPushButton[text="Cancel"] {
qproperty-text: "取消";
}
QMessageBox QPushButton[text="Close"] {
qproperty-text: "关闭";
}
QMessageBox QPushButton[text="Discard"] {
qproperty-text: "不保存";
}
QMessageBox QPushButton[text="Don't Save"] {
qproperty-text: "不保存";
}
QMessageBox QPushButton[text="Apply"] {
qproperty-text: "应用";
}
QMessageBox QPushButton[text="Reset"] {
qproperty-text: "重置";
}
QMessageBox QPushButton[text="Restore Defaults"] {
qproperty-text: "恢复默认";
}
QMessageBox QPushButton[text="Help"] {
qproperty-text: "帮助";
}
QMessageBox QPushButton[text="Save All"] {
qproperty-text: "保存全部";
}
QMessageBox QPushButton[text="&Yes"] {
qproperty-text: "";
}
QMessageBox QPushButton[text="Yes to &All"] {
qproperty-text: "全部都是";
}
QMessageBox QPushButton[text="&No"] {
qproperty-text: "";
}
QMessageBox QPushButton[text="N&o to All"] {
qproperty-text: "全部都不";
}
QMessageBox QPushButton[text="Abort"] {
qproperty-text: "终止";
}
QMessageBox QPushButton[text="Retry"] {
qproperty-text: "重试";
}
QMessageBox QPushButton[text="Ignore"] {
qproperty-text: "忽略";
}
"""
app = QApplication(sys.argv)
# 通过QSS样式的方式设置按钮文字
app.setStyleSheet(TextStyle)
# 由于年代久远Qt5的翻译功能没有更新还是用的旧的结构导致无法翻译
# 这里不使用需要修改ts源码重新编译成qm
# translator = QTranslator()
# print(translator.load(QLocale(), 'qt', '_', QLibraryInfo.location(
# QLibraryInfo.TranslationsPath)))
# app.installTranslator(translator)
QMessageBox.information(
None, 'information', '消息',
QMessageBox.Ok |
QMessageBox.Open |
QMessageBox.Save |
QMessageBox.Cancel |
QMessageBox.Close |
QMessageBox.Discard |
QMessageBox.Apply |
QMessageBox.Reset |
QMessageBox.RestoreDefaults |
QMessageBox.Help |
QMessageBox.SaveAll |
QMessageBox.Yes |
QMessageBox.YesToAll |
QMessageBox.No |
QMessageBox.NoToAll |
QMessageBox.Abort |
QMessageBox.Retry |
QMessageBox.Ignore
)
sys.exit()

View file

@ -3,6 +3,7 @@
- 目录 - 目录
- [消息对话框倒计时关闭](#1消息对话框倒计时关闭) - [消息对话框倒计时关闭](#1消息对话框倒计时关闭)
- [自定义图标等](#2自定义图标等) - [自定义图标等](#2自定义图标等)
- [消息框按钮文字汉化](#3消息框按钮文字汉化)
## 1、消息对话框倒计时关闭 ## 1、消息对话框倒计时关闭
[运行 CountDownClose.py](CountDownClose.py) [运行 CountDownClose.py](CountDownClose.py)
@ -15,4 +16,13 @@
## 2、自定义图标等 ## 2、自定义图标等
[运行 CustomColorIcon.py](CustomColorIcon.py) [运行 CustomColorIcon.py](CustomColorIcon.py)
![CustomColorIcon](ScreenShot/CustomColorIcon.png) ![CustomColorIcon](ScreenShot/CustomColorIcon.png)
## 3、消息框按钮文字汉化
[运行 ChineseText.py](ChineseText.py)
1. 因为Qt5的翻译文件还是沿用旧的Qt4的结构导致部分地方无法翻译
2. 可以通过手动重新编译翻译文件解决问题
3. 这里可以通过QSS特性修改按钮文字详细见代码
![ChineseText](ScreenShot/ChineseText.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

View file

@ -184,6 +184,7 @@ https://pyqt5.com 社区是专门针对PyQt5学习和提升开设的博客网站
- [QMessageBox](QMessageBox) - [QMessageBox](QMessageBox)
- [消息对话框倒计时关闭](QMessageBox/CountDownClose.py) - [消息对话框倒计时关闭](QMessageBox/CountDownClose.py)
- [自定义图标等](QMessageBox/CustomColorIcon.py) - [自定义图标等](QMessageBox/CustomColorIcon.py)
- [消息框按钮文字汉化](QMessageBox/ChineseText.py)
- [QFileSystemModel](QFileSystemModel) - [QFileSystemModel](QFileSystemModel)
- [自定义图标](QFileSystemModel/CustomIcon.py) - [自定义图标](QFileSystemModel/CustomIcon.py)
- [QGraphicsDropShadowEffect](QGraphicsDropShadowEffect) - [QGraphicsDropShadowEffect](QGraphicsDropShadowEffect)