MochiuWiki : SUSE, EC, PCB
案内
メインページ
最近の更新
おまかせ表示
MediaWiki についてのヘルプ
ツール
リンク元
関連ページの更新状況
特別ページ
ページ情報
We ask for
Donations
検索
個人用ツール
ログイン
Toggle dark mode
名前空間
ページ
議論
表示
閲覧
ソースを閲覧
履歴を表示
QMLの基礎 - ウインドウのソースを表示
提供: MochiuWiki : SUSE, EC, PCB
←
QMLの基礎 - ウインドウ
あなたには「このページの編集」を行う権限がありません。理由は以下の通りです:
この操作は、次のグループのいずれかに属する利用者のみが実行できます:
管理者
、new-group。
このページのソースの閲覧やコピーができます。
== 概要 == <br><br> == ウインドウのオープン / クローズ == ウィンドウの表示および非表示する等、ウィンドウ間のスイッチングを実装する手順を記載する。<br> <br> まず、QMLにおけるシグナルの構文を以下に示す。<br> <br> シグナル(<code>signal <シグナル名></code>)を宣言して、シグナルの定義を記述する。<br> シグナルの定義名は、プレフィックスに"<code>on</code>"という文字を付加して、シグナル名の先頭文字を大文字にする必要がある。<br> <syntaxhighlight lang="qml"> signal closeThisWindow onCloseThisWindow: { // Some code } </syntaxhighlight> <br> 以下の例では、メインウインドウの上ボタンを押下する時、メイン画面を非表示にしてサブウインドウを開く。<br> サブウインドウを閉じる時、メイン画面を再度表示する。<br> <br> シグナルは、以下の例のように、サブウィンドウにおいて関数として呼び出される。<br> <br> なお、.proファイルとmain.cppファイルは変更していない。<br> <syntaxhighlight lang="qml"> // AnotherWindow.qml import QtQuick 2.15 import QtQuick.Controls 2.15 import QtQuick.Window 2.15 Window { id: anotherWindow width:480 height:320 signal signalExit // シグナルの宣言 // Button to open the main application window Button { text: qsTr("メインウインドウに戻る") width: 180 height: 50 anchors.centerIn: parent onClicked: { anotherWindow.signalExit() // シグナルを発行する } } } </syntaxhighlight> <br> メインウインドウのqmlファイル(main.qmlファイル)には、ソフトウェアの主となるロジックを実装する。<br> <br> 以下の例では、メインウィンドウには2つのボタンがあり、各ボタンを押下する時、メインウィンドウが非表示になりサブウインドウが開く。<br> 各サブウィンドウのボタンを押下する時、サブウィンドウが閉じられて、メインウインドウが再度表示される。<br> <syntaxhighlight lang="qml"> // main.qmlファイル import QtQuick 2.15 import QtQuick.Controls 2.15 import QtQuick.Layouts 1.15 ApplicationWindow { id: mainWindow width: 640 height: 480 title: qsTr("Switching between windows in QML") visible: true Rectangle { anchors.fill: parent color: "white" GridLayout { id: grid anchors.fill: parent rows: 2 columns: 1 Rectangle { Layout.fillHeight: true Layout.fillWidth: true Layout.column: 1 Layout.row: 1 // Button to open the first secondary application window Button { text: qsTr("サブウインドウ 1 を開く") anchors.centerIn: parent width: 300 height: 50 onClicked: { firstWindow.show() // Open the first window mainWindow.hide() // Hide the main window } } } Rectangle { Layout.fillHeight: true Layout.fillWidth: true Layout.column: 1 Layout.row: 2 // Button to open the second secondary application window Button { text: qsTr("サブウインドウ 2 を開く") anchors.centerIn: parent width: 300 height: 50 onClicked: { secondWindow.show() // Open a second window mainWindow.hide() // Hide the main window } } } } } AnotherWindow { id: firstWindow title: qsTr("サブウインドウ 1") // The signal handler for the opening of the main window onSignalExit: { firstWindow.close() // Close the first window mainWindow.show() // Shows the main window } } AnotherWindow { id: secondWindow title: qsTr("サブウインドウ 2") // The signal handler for the opening of the main window onSignalExit: { secondWindow.close() // We close the second window mainWindow.show() // Shows the main window } } } </syntaxhighlight> <br><br> __FORCETOC__ [[カテゴリ:Qt]]
QMLの基礎 - ウインドウ
に戻る。
案内
メインページ
最近の更新
おまかせ表示
MediaWiki についてのヘルプ
ツール
リンク元
関連ページの更新状況
特別ページ
ページ情報
We ask for
Donations
Collapse