当前位置: 首页 > news >正文

聊城做网站的公司精英/百度云网页版入口

聊城做网站的公司精英,百度云网页版入口,手机网站制作机构,免费行情软件app合集一般情况下,需要翻译的内容处于UI相关的控件上,使用Qt提供的内置控件时,可以通过Qt Lingust直接再Widget相关的类中翻译; 如果有自定义控件,且控件中有需要翻译的内容的情形的处理: 1、显示添加翻译相关的…

一般情况下,需要翻译的内容处于UI相关的控件上,使用Qt提供的内置控件时,可以通过Qt Lingust直接再Widget相关的类中翻译;

如果有自定义控件,且控件中有需要翻译的内容的情形的处理:

1、显示添加翻译相关的代码;

2、将自定义控件写成插件,利用内置控件相同的机制来进行翻译;

代码

main.cpp

#include "QtVSMultiLanguage.h"
#include <QtWidgets/QApplication>
#include "Linguist.h"int main(int argc, char *argv[])
{QApplication a(argc, argv);CLinguist* lin = CLinguist::GetLinguistInstance();lin->ChangeLanguage(Language::zh_cn);QtVSMultiLanguage w;w.show();return a.exec();
}

 Linguist.h

// Linguist.h
#pragma once
/*
语言家,配置当前系统的语言
*/#include <QObject>
#include <qtranslator.h>enum Language
{zh_cn,en_us,undefined
};class CLinguist :public QObject
{Q_OBJECT
private:CLinguist();public:// 当前语言 简体中文、英文、未定义Language m_CurrentLanguage = Language::undefined;// 切换语言void ChangeLanguage(Language lan);static  CLinguist * GetLinguistInstance();
private:static CLinguist * linguist;QTranslator * m_trans;
signals:// 语言切换信号,通知当前系统语言已经被切换void LanguageChaned();
};

Linguist.cpp


#include "Linguist.h"
#include <QtCore/QCoreApplication>CLinguist * CLinguist::linguist = nullptr;
CLinguist::CLinguist() :m_trans(new QTranslator)
{
}CLinguist * CLinguist::GetLinguistInstance()
{if (nullptr == linguist){linguist = new CLinguist;}return linguist;
}void CLinguist::ChangeLanguage(Language lan)
{if (lan == this->m_CurrentLanguage || lan == Language::undefined) return;bool ret;switch (lan){case zh_cn:if (nullptr != m_trans){qApp->removeTranslator(m_trans);}ret = m_trans->load("qtvsmultilanguage_zh.qm");if (ret){qApp->installTranslator(m_trans);}break;case en_us:if (nullptr != m_trans){qApp->removeTranslator(m_trans);}ret = m_trans->load("qtvsmultilanguage_en.qm");if (ret){qApp->installTranslator(m_trans);}break;default:break;}if (ret){this->m_CurrentLanguage = lan;// 发出语言被切换的信号emit LanguageChaned();}
}

 QtVSMultiLanguage.ui

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"><class>QtVSMultiLanguageClass</class><widget class="QMainWindow" name="QtVSMultiLanguageClass"><property name="geometry"><rect><x>0</x><y>0</y><width>653</width><height>416</height></rect></property><property name="windowTitle"><string>QtVSMultiLanguage</string></property><widget class="QWidget" name="centralWidget"><widget class="QWidget" name="layoutWidget"><property name="geometry"><rect><x>50</x><y>20</y><width>354</width><height>185</height></rect></property><layout class="QVBoxLayout" name="verticalLayout"><item><layout class="QHBoxLayout" name="horizontalLayout"><item><widget class="QLabel" name="UserNameLabel"><property name="text"><string>UserName:</string></property></widget></item><item><spacer name="horizontalSpacer"><property name="orientation"><enum>Qt::Horizontal</enum></property><property name="sizeHint" stdset="0"><size><width>28</width><height>20</height></size></property></spacer></item><item><widget class="QTextEdit" name="UserNametextEdit"/></item></layout></item><item><layout class="QHBoxLayout" name="horizontalLayout_2"><item><widget class="QLabel" name="PassWordLabel"><property name="text"><string>PassWord:</string></property></widget></item><item><spacer name="horizontalSpacer_2"><property name="orientation"><enum>Qt::Horizontal</enum></property><property name="sizeHint" stdset="0"><size><width>28</width><height>20</height></size></property></spacer></item><item><widget class="QTextEdit" name="PassWordtextEdit"/></item></layout></item><item><layout class="QHBoxLayout" name="horizontalLayout_3"><item><widget class="QPushButton" name="SwitchpushButton"><property name="text"><string>SwitchLanguage</string></property></widget></item><item><spacer name="horizontalSpacer_3"><property name="orientation"><enum>Qt::Horizontal</enum></property><property name="sizeHint" stdset="0"><size><width>40</width><height>20</height></size></property></spacer></item><item><widget class="QPushButton" name="LoginpushButton"><property name="text"><string>Login</string></property></widget></item><item><spacer name="horizontalSpacer_4"><property name="orientation"><enum>Qt::Horizontal</enum></property><property name="sizeHint" stdset="0"><size><width>40</width><height>20</height></size></property></spacer></item><item><widget class="QPushButton" name="CancelpushButton"><property name="text"><string>Cancel</string></property></widget></item></layout></item></layout></widget><widget class="ForceLinePointWidget" name="PointInfoWidget"><property name="geometry"><rect><x>90</x><y>250</y><width>440</width><height>40</height></rect></property><property name="toolTip"><string>The current time</string></property><property name="whatsThis"><string>The analog clock widget displays the current time.</string></property><property name="pointName"><string>FemurHeadCenter</string></property></widget></widget><widget class="QMenuBar" name="menuBar"><property name="geometry"><rect><x>0</x><y>0</y><width>653</width><height>23</height></rect></property></widget><widget class="QToolBar" name="mainToolBar"><attribute name="toolBarArea"><enum>TopToolBarArea</enum></attribute><attribute name="toolBarBreak"><bool>false</bool></attribute></widget><widget class="QStatusBar" name="statusBar"/></widget><layoutdefault spacing="6" margin="11"/><customwidgets><customwidget><class>ForceLinePointWidget</class><extends>QWidget</extends><header>ForceLinePointWidget.h</header></customwidget></customwidgets><resources><include location="QtVSMultiLanguage.qrc"/></resources><connections/>
</ui>

https://gitee.com/beibeix/qt-samples/tree/master/QtVSMultiLanguage

结果

 

http://www.jmfq.cn/news/4907035.html

相关文章:

  • 信阳住房和城乡建设局网站/市场营销推广
  • 做网站界面需要注意什么问题/赣州网站建设
  • 建设网站服务器/百度网盘客服电话24小时
  • 大型营销型网站建设/上海关键词排名提升
  • 建云购网站吗/关键词排名零芯互联排名
  • 网站推广策划方案范文/个人怎么注册自己的网站
  • 在线图片编辑源码/seo资源是什么意思
  • 哪些网站可以做相册视频/广州百度seo 网站推广
  • 网站直播怎样做/宁波网站seo诊断工具
  • 外贸婚纱网站 侵权/同城推广平台有哪些
  • 网站开发需要掌握的知识/佛山网络推广培训
  • 中国建设银行最新招聘信息网站/微信推广怎么弄
  • 剑灵代做装备网站/排名优化系统
  • 如何做单网页网站/就业seo好还是sem
  • 捕鱼游戏在哪做网站/外贸seo软件
  • 160 作者 网站建设/seo销售话术开场白
  • 微信建设网站找哪家/今日国际军事新闻头条
  • html5官方网站开发流程/广告投放的方式有哪些
  • 国内知名网站制作公司/宁波seo网络推广渠道介绍
  • 秦皇岛网站制作小程序开发/徐州做网站的公司
  • 自己给自己网站做推广/百度收录量
  • 网站空间域名续费/网址域名
  • 邹城哪个公司做网站好/百度推广竞价
  • 郑州定制网站建设/网络平台宣传方式有哪些
  • 织梦个人网站模板/百度seo咋做
  • 泉州pc网站开发/百度指数查询app
  • 注册网站合集/电商网站项目
  • 南乐网站建设电话/百度网站优化方案
  • 电商网站建设商业计划书/seo优化步骤
  • 企业做网站时应注意的事项/谷歌seo服务商