<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[beginner question: qml if else with a switch]]></title><description><![CDATA[<p dir="auto">Hi,<br />
I wanna do the following - but have absolute no idea how!</p>
<p dir="auto">App with a switch.</p>
<pre><code>Icon {
               if Switch.on (
                   width: units.gu(5)
                   height: units.gu(5)
                   name: 'flash-on'       
               )
              else if (
                   width: units.gu(5)
                   height: units.gu(5)
                   name: 'flash-off'
                )
              else (
                   width: units.gu(5)
                   height: units.gu(5)
                   name: 'cancel'
              )  
           }
</code></pre>
<p dir="auto"><a href="https://docs.ubports.com/projects/icons/en/latest/" target="_blank" rel="noopener noreferrer nofollow ugc">https://docs.ubports.com/projects/icons/en/latest/</a></p>
]]></description><link>https://forums.ubports.com/topic/10568/beginner-question-qml-if-else-with-a-switch</link><generator>RSS for Node</generator><lastBuildDate>Wed, 13 May 2026 14:11:27 GMT</lastBuildDate><atom:link href="https://forums.ubports.com/topic/10568.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 07 Nov 2024 05:43:50 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to beginner question: qml if else with a switch on Mon, 11 Nov 2024 19:53:39 GMT]]></title><description><![CDATA[<p dir="auto">Yeah I agree. You don't fully grasp yet how QML works. We all had that time when we are starting especially when coming from non-declarative language <img src="https://forums.ubports.com/assets/plugins/nodebb-plugin-emoji/emoji/android/1f604.png?v=56a73af4c47" class="not-responsive emoji emoji-android emoji--smile" style="height:23px;width:auto;vertical-align:middle" title="😄" alt="😄" /> You should really try reading a bit even just the basics of it. One key thing is that Javascript is used for logic within QML, ideally only for front end logic but you could also do everything with just QML and JS.</p>
<p dir="auto">For your example, you can simply add an inline conditional statement for the <code>icon.name</code> property. Or for more advanced use especially if you intend to add more changes, you can use <code>States</code>.</p>
<p dir="auto">Here's a sample one for the inline:</p>
<pre><code>icon.name: switch.checked ? "tick" : "close"
</code></pre>
]]></description><link>https://forums.ubports.com/post/83357</link><guid isPermaLink="true">https://forums.ubports.com/post/83357</guid><dc:creator><![CDATA[kugiigi]]></dc:creator><pubDate>Mon, 11 Nov 2024 19:53:39 GMT</pubDate></item><item><title><![CDATA[Reply to beginner question: qml if else with a switch on Thu, 07 Nov 2024 13:57:51 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ifelse" aria-label="Profile: ifelse">@<bdi>ifelse</bdi></a> It seems you might benefit from a general introductory level QML tutorial.</p>
<p dir="auto">I can recommend <a href="https://youtube.com/playlist?list=PLB22HyVdO1GkLFrvRi5vIo5XcWS0EflxD&amp;si=2evZroryRf-s_q94" target="_blank" rel="noopener noreferrer nofollow ugc">this one</a>.</p>
]]></description><link>https://forums.ubports.com/post/83254</link><guid isPermaLink="true">https://forums.ubports.com/post/83254</guid><dc:creator><![CDATA[arubislander]]></dc:creator><pubDate>Thu, 07 Nov 2024 13:57:51 GMT</pubDate></item><item><title><![CDATA[Reply to beginner question: qml if else with a switch on Thu, 07 Nov 2024 13:23:16 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ikoz" aria-label="Profile: ikoz">@<bdi>ikoz</bdi></a></p>
<p dir="auto">could you be so kind an give me a example</p>
<p dir="auto">beacuse how to define a variable in qml code:</p>
<ul>
<li>add the icon</li>
</ul>
<p dir="auto">here is the default Main.qml<br />
when create a new project.</p>
<pre><code>import QtQuick 2.7
import QtQuick.Controls 2.2
import Lomiri.Components 1.3
import QtQuick.Layouts 1.3
import Qt.labs.settings 1.0

import Greeter 1.0

ApplicationWindow {
    id: root
    objectName: 'mainView'

    width: units.gu(45)
    height: units.gu(75)
    visible: true

    Greeter {
        id: greeter
        name: "Rust + Ubuntu Touch"
    }

    Page {
        anchors.fill: parent

        header: PageHeader {
            id: header
            title: i18n.tr('bla')
        }

            Icon {
                width: units.gu(5)
                height: units.gu(5)
                name: 'cancel'
                
            }

        ColumnLayout {
            spacing: units.gu(2)
            anchors {
                margins: units.gu(2)
                top: header.bottom
                left: parent.left
                right: parent.right
                bottom: parent.bottom
            }

            Item {
                Layout.fillHeight: true
            }

            Label {
                id: label
                text: i18n.tr('Press the button below!')
            }

            Button {
                text: i18n.tr('Compute greeting')
                onClicked: {
                    label.text = greeter.compute_greetings("Hello, ");
                }
            }

            Switch {
                checked: off
                onClicked: {
                        label.text = greeter.compute_greetings("sw on");
                }

            }


            Item {
                Layout.fillHeight: true
            }
        }
    }
}
</code></pre>
]]></description><link>https://forums.ubports.com/post/83253</link><guid isPermaLink="true">https://forums.ubports.com/post/83253</guid><dc:creator><![CDATA[ifelse]]></dc:creator><pubDate>Thu, 07 Nov 2024 13:23:16 GMT</pubDate></item><item><title><![CDATA[Reply to beginner question: qml if else with a switch on Thu, 07 Nov 2024 12:47:55 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ifelse" aria-label="Profile: ifelse">@<bdi>ifelse</bdi></a> Just modify the <code>icon.name</code> variable from a separate function</p>
]]></description><link>https://forums.ubports.com/post/83251</link><guid isPermaLink="true">https://forums.ubports.com/post/83251</guid><dc:creator><![CDATA[ikoz]]></dc:creator><pubDate>Thu, 07 Nov 2024 12:47:55 GMT</pubDate></item></channel></rss>