Results 1 to 3 of 3

Thread: Displaying Chnise fonts in GUI

  1. #1

    Default Displaying Chnise fonts in GUI

    Hi,

    My application should support different languages. Currently i am trying with Japanese. But it is not displayed. My code is

    main.cpp

    Qt Code:
    1. #include <QApplication>
    2. #include <QTranslator>
    3. #include "form.h"
    4. int main(int argc, char *argv[])
    5. {
    6.  
    7. QApplication app(argc, argv);
    8. QTranslator translator;
    9. translator.load(":/translations/i18n_jp.qm");
    10. qApp->installTranslator(&translator);
    11. Form *window = new Form ;
    12. window->show();
    13. return app.exec();
    14. }
    To copy to clipboard, switch view to plain text mode 

    form.cpp
    Qt Code:
    1. #include "form.h"
    2. #include "ui_form.h"
    3.  
    4. Form::Form(QWidget *parent) :
    5. QWidget(parent),
    6. ui(new Ui::Form)
    7. {
    8. ui->setupUi(this);
    9. ui->label->setText(tr("Hello"));
    10. this->setWindowTitle(tr("Internationalization Example"));
    11. }
    12.  
    13. Form::~Form()
    14. {
    15. delete ui;
    16. }
    To copy to clipboard, switch view to plain text mode 

    form.h

    Qt Code:
    1. #ifndef FORM_H
    2. #define FORM_H
    3.  
    4. #include <QWidget>
    5.  
    6. namespace Ui {
    7. class Form;
    8. }
    9.  
    10. class Form : public QWidget
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. explicit Form(QWidget *parent = 0);
    16. ~Form();
    17.  
    18. private:
    19. Ui::Form *ui;
    20. };
    21.  
    22. #endif // FORM_H
    To copy to clipboard, switch view to plain text mode 

    pro file

    #-------------------------------------------------
    #
    # Project created by QtCreator 2010-10-25T14:51:37
    #
    #-------------------------------------------------

    HEADERS = mainwindow.h \
    form.h
    SOURCES += main.cpp\
    mainwindow.cpp \
    form.cpp
    RESOURCES += Chinise.qrc
    TRANSLATIONS += translations/i18n_ar.ts \
    translations/i18n_cs.ts \
    translations/i18n_de.ts \
    translations/i18n_el.ts \
    translations/i18n_en.ts \
    translations/i18n_eo.ts \
    translations/i18n_fr.ts \
    translations/i18n_it.ts \
    translations/i18n_jp.ts \
    translations/i18n_ko.ts \
    translations/i18n_no.ts \
    translations/i18n_ru.ts \
    translations/i18n_sv.ts \
    translations/i18n_zh.ts

    FORMS += \
    form.ui

    please help me

  2. #2
    Join Date
    Oct 2010
    Posts
    37
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Displaying Chnise fonts in GUI

    Try this:
    translator.load("translations/i18n_jp");

    And make sure you convert the .ts files from QLinguist by clicking File->Release

  3. #3

    Default Re: Displaying Chnise fonts in GUI

    It is working with below mentioned code. If i create UI through designer or some thing else ,that time it is not working.

    mainwindow.cpp
    Qt Code:
    1. /****************************************************************************
    2. **
    3. ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
    4. ** All rights reserved.
    5. ** Contact: Nokia Corporation (qt-info@nokia.com)
    6. **
    7. ** This file is part of the examples of the Qt Toolkit.
    8. **
    9. ** $QT_BEGIN_LICENSE:BSD$
    10. ** You may use this file under the terms of the BSD license as follows:
    11. **
    12. ** "Redistribution and use in source and binary forms, with or without
    13. ** modification, are permitted provided that the following conditions are
    14. ** met:
    15. ** * Redistributions of source code must retain the above copyright
    16. ** notice, this list of conditions and the following disclaimer.
    17. ** * Redistributions in binary form must reproduce the above copyright
    18. ** notice, this list of conditions and the following disclaimer in
    19. ** the documentation and/or other materials provided with the
    20. ** distribution.
    21. ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
    22. ** the names of its contributors may be used to endorse or promote
    23. ** products derived from this software without specific prior written
    24. ** permission.
    25. **
    26. ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    27. ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    28. ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    29. ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    30. ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    31. ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    32. ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    33. ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    34. ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    35. ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    36. ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
    37. ** $QT_END_LICENSE$
    38. **
    39. ****************************************************************************/
    40.  
    41. #include <QtGui>
    42.  
    43. #include "mainwindow.h"
    44.  
    45. MainWindow::MainWindow()
    46. {
    47. centralWidget = new QWidget;
    48. setCentralWidget(centralWidget);
    49.  
    50. createGroupBox();
    51.  
    52. listWidget = new QListWidget;
    53. for (int i = 0; i<4; ++i)
    54. listWidget->addItem(tr("First"));
    55.  
    56. QVBoxLayout *mainLayout = new QVBoxLayout;
    57. mainLayout->addWidget(groupBox);
    58. mainLayout->addWidget(listWidget);
    59. centralWidget->setLayout(mainLayout);
    60.  
    61. exitAction = new QAction(tr("E&xit"), this);
    62. connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
    63.  
    64. fileMenu = menuBar()->addMenu(tr("&File"));
    65. fileMenu->setPalette(QPalette(Qt::red));
    66. fileMenu->addAction(exitAction);
    67.  
    68. setWindowTitle(tr("Language: %1").arg(tr("English")));
    69. statusBar()->showMessage(tr("Internationalization Example"));
    70.  
    71. if (tr("LTR") == "RTL")
    72. setLayoutDirection(Qt::RightToLeft);
    73.  
    74. }
    75.  
    76. void MainWindow::createGroupBox()
    77. {
    78. groupBox = new QGroupBox(tr("View"));
    79. perspectiveRadioButton = new QRadioButton(tr("Perspective"));
    80. isometricRadioButton = new QRadioButton(tr("Isometric"));
    81. obliqueRadioButton = new QRadioButton(tr("Oblique"));
    82. perspectiveRadioButton->setChecked(true);
    83.  
    84. QVBoxLayout *groupBoxLayout = new QVBoxLayout;
    85. groupBoxLayout->addWidget(perspectiveRadioButton);
    86. groupBoxLayout->addWidget(isometricRadioButton);
    87. groupBoxLayout->addWidget(obliqueRadioButton);
    88. groupBox->setLayout(groupBoxLayout);
    89. }
    To copy to clipboard, switch view to plain text mode 

    mainwindow.h
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include <QVBoxLayout>
    6.  
    7. class QAction;
    8. class QGroupBox;
    9. class QLabel;
    10. class QMenu;
    11.  
    12. class MainWindow : public QMainWindow
    13. {
    14. Q_OBJECT
    15.  
    16. public:
    17. MainWindow();
    18.  
    19. private:
    20. void createGroupBox();
    21.  
    22. QWidget *centralWidget;
    23. QLabel *label;
    24. QGroupBox *groupBox;
    25. QListWidget *listWidget;
    26. QRadioButton *perspectiveRadioButton;
    27. QRadioButton *isometricRadioButton;
    28. QRadioButton *obliqueRadioButton;
    29. QMenu *fileMenu;
    30. QAction *exitAction;
    31.  
    32. };
    33.  
    34. #endif
    To copy to clipboard, switch view to plain text mode 
    main.cpp
    Qt Code:
    1. #include <QApplication>
    2. #include "mainwindow.h"
    3. #include <QTranslator>
    4. #include "form.h"
    5. int main(int argc, char *argv[])
    6. {
    7.  
    8. QApplication app(argc, argv);
    9. QTranslator translator;
    10. translator.load(":/translations/i18n_jp.qm");
    11. qApp->installTranslator(&translator);
    12. MainWindow *window = new MainWindow ;
    13. window->show();
    14. return app.exec();
    15. }
    To copy to clipboard, switch view to plain text mode 

    Please help me

    Thanks

    Yuvaraj

Similar Threads

  1. Non-Antialias fonts
    By efan in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 4th March 2010, 20:08
  2. Changing Fonts
    By QbelcorT in forum Qt Programming
    Replies: 6
    Last Post: 13th April 2009, 13:57
  3. About Fonts
    By QbelcorT in forum Qt Programming
    Replies: 1
    Last Post: 2nd April 2009, 18:58
  4. How to use qpf fonts
    By yagabey in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 18th September 2008, 08:56
  5. Logical fonts?
    By sdfisher in forum Qt Programming
    Replies: 1
    Last Post: 1st March 2007, 14:01

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.