qt实现中英文切换源码(qt使用中文)
本文目录一览:
qt中的英文errorstring能变成中文显示吗
方法一:
w.setWindowTitle(QString::fromUtf8("控制主窗口"));
//多窗口swtich设计 程序
#include QtGui/QApplication
#include "mainwindow.h"
#include"logindlg.h"
#include QString
//#include QTextCodec//为了显中文
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
mainwindow w;
logindlg login;//creat object of logindlg
//为了显中文
login.setWindowTitle(QString::fromUtf8("登陆窗口"));
if(login.exec()==QDialog::Accepted)
{
w.show();
w.setWindowTitle(QString::fromUtf8("控制主窗口"));
return a.exec();
}
else
return 0;
}
方法二:
可以在ui 的窗口设置那windowtitle 那设置相要的标题名字
用MessageBox:要加上头文件:
#include QtGui //use QMessageBox header file
QMessageBox::warning(this,tr("Warming"),tr("username or password error"),
tr("Yes"),tr("No"));
关于Qt界面转换中英文的问题
好像是你的实参传递不对。
你可以把setText(tr(text.toLatin1)); 改为setText(tr(“测试”));试试,如果界面能正常显示测试二字,说明就是实参有错误。
而且你那个 QString text = 的那一串,没看懂.......
你可以看看你这一串是什么值。是不是 你预期的字符串。
qml中英文切换部分不能切换
运行的版本不一样。
程序中实现多语言有Qt自己的一套机制,然而目前在5.9版本下该机制无法在程序运行期间动态切换语言。
首先在工程文件pro中加入TRANSLATIONS=zh_CN。tsen_US。ts两个翻译文件,支持中英文两种语言切换,在工程目录下cmd执行。执行完后在代码目录里就可以看到生成了。
如何用qt实现界面的切换
界面one图形如下:
one.h
[cpp] view plain copy
#ifndef ONE_H
#define ONE_H
#include QWidget
class Two;
namespace Ui {
class One;
}
class One : public QWidget
{
Q_OBJECT
public:
explicit One(QWidget *parent = 0);
~One();
signals:
void display(int number);
private slots:
void on_nextPushButton_clicked();
private:
Ui::One *ui;
Two *two;
};
#endif // ONE_H
one.cpp
[cpp] view plain copy
#include "one.h"
#include "ui_one.h"
#include "two.h"
#include "widget.h"
One::One(QWidget *parent) :
QWidget(parent),
ui(new Ui::One)
{
ui-setupUi(this);
}
One::~One()
{
delete ui;
}
void One::on_nextPushButton_clicked()
{
emit display(1);
}
界面two
界面two图形如下:
two.h
[cpp] view plain copy
#ifndef TWO_H
#define TWO_H
#include QWidget
namespace Ui {
class Two;
}
class Two : public QWidget
{
Q_OBJECT
public:
explicit Two(QWidget *parent = 0);
~Two();
signals:
void display(int number);
private slots:
void on_previousPushButton_clicked();
void on_nextPushButton_clicked();
private:
Ui::Two *ui;
};
#endif // TWO_H
two.cpp
[cpp] view plain copy
#include "two.h"
#include "ui_two.h"
Two::Two(QWidget *parent) :
QWidget(parent),
ui(new Ui::Two)
{
ui-setupUi(this);
}
Two::~Two()
{
delete ui;
}
void Two::on_previousPushButton_clicked()
{
emit display(0);
}
void Two::on_nextPushButton_clicked()
{
emit display(2);
}
界面three
界面three图形如下:
three.h
[cpp] view plain copy
#ifndef THREE_H
#define THREE_H
#include QWidget
namespace Ui {
class Three;
}
class Three : public QWidget
{
Q_OBJECT
public:
explicit Three(QWidget *parent = 0);
~Three();
signals:
void display(int number);
private slots:
void on_previousPushButton_clicked();
private:
Ui::Three *ui;
};
#endif // THREE_H
three.cpp
[cpp] view plain copy
#include "three.h"
#include "ui_three.h"
Three::Three(QWidget *parent) :
QWidget(parent),
ui(new Ui::Three)
{
ui-setupUi(this);
}
Three::~Three()
{
delete ui;
}
void Three::on_previousPushButton_clicked()
{
emit display(1);
}
主界面
widget.h
[cpp] view plain copy
#ifndef WIDGET_H
#define WIDGET_H
#include QWidget
class One;
class Two;
class Three;
class QStackedLayout;
class QVBoxLayout;
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
private:
One *one;
Two *two;
Three *three;
QStackedLayout *stackLayout;
QVBoxLayout *mainLayout;
};
#endif // WIDGET_H
widget.cpp
[cpp] view plain copy
#include "widget.h"
#include "ui_widget.h"
#include "one.h"
#include "two.h"
#include "three.h"
#include QStackedLayout
#include QPushButton
#include QVBoxLayout
Widget::Widget(QWidget *parent) :
QWidget(parent)
{
setFixedSize(400, 300);
one = new One;
two = new Two;
three = new Three;
stackLayout = new QStackedLayout;
stackLayout-addWidget(one);
stackLayout-addWidget(two);
stackLayout-addWidget(three);
connect(one, One::display, stackLayout, QStackedLayout::setCurrentIndex); // 0
connect(two, Two::display, stackLayout, QStackedLayout::setCurrentIndex); // 1
connect(three, Three::display, stackLayout, QStackedLayout::setCurrentIndex); // 2
mainLayout = new QVBoxLayout;
mainLayout-addLayout(stackLayout);
setLayout(mainLayout);
}
Widget::~Widget()
{
}
main.cpp
[cpp] view plain copy
#include "widget.h"
#include QApplication
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}