Advertisement
mercibac

main.qml

May 25th, 2021
1,498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QML 2.09 KB | None | 0 0
  1. import QtQuick 2.6
  2. import QtQuick.Controls 1.5
  3.  
  4. ApplicationWindow {
  5.     id: applicationWindow
  6.     visible: true
  7.     width: 640
  8.     height: 480
  9.  
  10.     Label {
  11.         id: helloLabel
  12.         height: 50
  13.         anchors {
  14.             top: parent.top
  15.             left: parent.left
  16.             right: parent.horizontalCenter
  17.             margins: 10
  18.         }
  19.     }
  20.  
  21.     ComboBox {
  22.         id: comboBox
  23.         anchors {
  24.             top: parent.top
  25.             left: parent.horizontalCenter
  26.             right: parent.right
  27.             margins: 10
  28.         }
  29.  
  30.         model: ["ru_RU", "en_US"]
  31.  
  32.         // If you change the text, initialize the translation unit via C++ Layer
  33.         onCurrentTextChanged: {
  34.             qmlTranslator.setTranslation(comboBox.currentText)
  35.         }
  36.     }
  37.  
  38.     Label {
  39.         id: labelText
  40.         wrapMode: Text.Wrap
  41.         anchors {
  42.             top: helloLabel.bottom
  43.             left: parent.left
  44.             right: parent.right
  45.             margins: 10
  46.         }
  47.     }
  48.  
  49.     // Connect to an interpreter object
  50.     Connections {
  51.         target: qmlTranslator // was registered in main.cpp
  52.         onLanguageChanged: {
  53.             // upon receipt of the signal to change the language
  54.             retranslateUi() // initialize interface translation
  55.         }
  56.     }
  57.  
  58.     // interface translation function
  59.     function retranslateUi() {
  60.         applicationWindow.title = qsTr("Hello World")
  61.         helloLabel.text = qsTr("Hello World")
  62.         labelText.text = qsTr(
  63.                     "The QTranslator class provides internationalization"
  64.                     + "support for text output.An object of this class contains "
  65.                     + "a set of translations from a source language to a target language. "
  66.                     + "QTranslator provides functions to look up translations in a translation file. "
  67.                     + "Translation files are created using Qt Linguist.")
  68.     }
  69.  
  70.     // Start translating the application window when the application was created
  71.     Component.onCompleted: {
  72.         retranslateUi()
  73.     }
  74. }
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement