From ac9fdaf769f9e265c92a658e4299b1ba98626aeb Mon Sep 17 00:00:00 2001 From: Irony <892768447@qq.com> Date: Wed, 10 Jul 2019 14:10:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B6=88=E6=81=AF=E6=A1=86=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E6=96=87=E5=AD=97=E6=B1=89=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .settings/org.eclipse.core.resources.prefs | 1 + QMessageBox/ChineseText.py | 114 +++++++++++++++++++++ QMessageBox/README.md | 12 ++- QMessageBox/ScreenShot/ChineseText.png | Bin 0 -> 9161 bytes README.md | 1 + 5 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 QMessageBox/ChineseText.py create mode 100644 QMessageBox/ScreenShot/ChineseText.png 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 0000000000000000000000000000000000000000..e2cc9b97e1773d15bba50187dcc981b8b0076bb2 GIT binary patch literal 9161 zcma*Ndpy(q8$Yg8D&f8pLa6S#D?&LWhgqV7v*eIDtP(;jhBdQII^B`vd_JG1VL2{l zTP1`XatvdY!^|-3fZ6z=KHqqAOB<_eV*BOx3keB{ znO--s6%rC&+5G)v@1D(X-GO&|g@ld@nVJ~cJ<6CH70Wr~L2Oy1&d%%RJXL=j`ucXk z?e8L@$~cv6?^AQa-kAOEqXp5ntA(JcJEH*U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