diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs index 5b3e067..ce12414 100644 --- a/.settings/org.eclipse.core.resources.prefs +++ b/.settings/org.eclipse.core.resources.prefs @@ -32,6 +32,7 @@ encoding//QListView/CustomWidgetSortItem.py=utf-8 encoding//QListView/SortItemByRole.py=utf-8 encoding//QListWidget/FoldWidget.py=utf-8 encoding//QListWidget/SignalsExample.py=utf-8 +encoding//QMessageBox/ChineseText.py=utf-8 encoding//QMessageBox/CustomColorIcon.py=utf-8 encoding//QProgressBar/Lib/WaterRippleProgressBar.py=utf-8 encoding//QProgressBar/MetroCircleProgress.py=utf-8 diff --git a/QMessageBox/ChineseText.py b/QMessageBox/ChineseText.py new file mode 100644 index 0000000..e1e766d --- /dev/null +++ b/QMessageBox/ChineseText.py @@ -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() diff --git a/QMessageBox/README.md b/QMessageBox/README.md index 93aa2b1..84a1e91 100644 --- a/QMessageBox/README.md +++ b/QMessageBox/README.md @@ -3,6 +3,7 @@ - 目录 - [消息对话框倒计时关闭](#1消息对话框倒计时关闭) - [自定义图标等](#2自定义图标等) + - [消息框按钮文字汉化](#3消息框按钮文字汉化) ## 1、消息对话框倒计时关闭 [运行 CountDownClose.py](CountDownClose.py) @@ -15,4 +16,13 @@ ## 2、自定义图标等 [运行 CustomColorIcon.py](CustomColorIcon.py) -![CustomColorIcon](ScreenShot/CustomColorIcon.png) \ No newline at end of file +![CustomColorIcon](ScreenShot/CustomColorIcon.png) + +## 3、消息框按钮文字汉化 +[运行 ChineseText.py](ChineseText.py) + +1. 因为Qt5的翻译文件还是沿用旧的Qt4的结构导致部分地方无法翻译 +2. 可以通过手动重新编译翻译文件解决问题 +3. 这里可以通过QSS特性修改按钮文字,详细见代码 + +![ChineseText](ScreenShot/ChineseText.png) \ No newline at end of file diff --git a/QMessageBox/ScreenShot/ChineseText.png b/QMessageBox/ScreenShot/ChineseText.png new file mode 100644 index 0000000..e2cc9b9 Binary files /dev/null and b/QMessageBox/ScreenShot/ChineseText.png differ diff --git a/README.md b/README.md index 895a798..7cacd7a 100644 --- a/README.md +++ b/README.md @@ -184,6 +184,7 @@ https://pyqt5.com 社区是专门针对PyQt5学习和提升开设的博客网站 - [QMessageBox](QMessageBox) - [消息对话框倒计时关闭](QMessageBox/CountDownClose.py) - [自定义图标等](QMessageBox/CustomColorIcon.py) + - [消息框按钮文字汉化](QMessageBox/ChineseText.py) - [QFileSystemModel](QFileSystemModel) - [自定义图标](QFileSystemModel/CustomIcon.py) - [QGraphicsDropShadowEffect](QGraphicsDropShadowEffect)