/usr/share/qt5/doc/qtquickcontrols/qtquickcontrols-touch-example.html is in qtquickcontrols5-doc-html 5.5.1-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 | <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qtquickcontrols-examples.qdoc -->
<title>Qt Quick Controls - Touch Gallery | Qt Quick Controls 5.5</title>
<link rel="stylesheet" type="text/css" href="style/offline.css" />
</head>
<body>
<div class="header" id="qtdocheader">
<div class="main">
<div class="main-rounded">
<div class="navigationbar">
<ul>
<li>Qt 5.5</li>
<li><a href="qtquickcontrols-index.html">Qt Quick Controls</a></li>
<li>Qt Quick Controls - Touch Gallery</li>
<li id="buildversion">Qt 5.5.1 Reference Documentation</li>
</ul>
</div>
</div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#running-the-example">Running the Example</a></li>
<li class="level1"><a href="#creating-the-main-page">Creating the Main Page</a></li>
<li class="level1"><a href="#navigating-in-the-application">Navigating in the Application</a></li>
<li class="level1"><a href="#creating-push-buttons-and-switches">Creating Push Buttons and Switches</a></li>
<li class="level1"><a href="#creating-sliders">Creating Sliders</a></li>
<li class="level1"><a href="#indicating-progress">Indicating Progress</a></li>
<li class="level1"><a href="#creating-tabs">Creating Tabs</a></li>
<li class="level1"><a href="#creating-text-input-fields">Creating Text Input Fields</a></li>
<li class="level1"><a href="#creating-scrolling-lists">Creating Scrolling Lists</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Qt Quick Controls - Touch Gallery</h1>
<span class="subtitle"></span>
<!-- $$$touch-description -->
<div class="descr"> <a name="details"></a>
<p class="centerAlign"><img src="images/qtquickcontrols-example-touch.png" alt="" /></p><p><i>Touch Gallery</i> demonstrates how to implement a UI suitable for touch input using the following <a href="qtquickcontrols-index.html">Qt Quick Controls</a>:</p>
<ul>
<li><a href="qml-qtquick-controls-applicationwindow.html">ApplicationWindow</a></li>
<li><a href="qml-qtquick-controls-button.html">Button</a></li>
<li><a href="qml-qtquick-controls-progressbar.html">ProgressBar</a></li>
<li><a href="qml-qtquick-controls-scrollview.html">ScrollView</a></li>
<li><a href="qml-qtquick-controls-slider.html">Slider</a></li>
<li><a href="qml-qtquick-controls-stackview.html">StackView</a></li>
<li><a href="qml-qtquick-controls-switch.html">Switch</a></li>
<li><a href="qml-qtquick-controls-tab.html">Tab</a></li>
<li><a href="qml-qtquick-controls-tabview.html">TabView</a></li>
<li><a href="qml-qtquick-controls-textfield.html">TextField</a></li>
</ul>
<p>The appearance of the controls is customized by using <a href="qtquickcontrolsstyles-index.html">Qt Quick Controls Styles</a>.</p>
<a name="running-the-example"></a>
<h2 id="running-the-example">Running the Example</h2>
<p>To run the example from Qt Creator, open the <b>Welcome</b> mode and select the example from <b>Examples</b>. For more information, visit Building and Running an Example.</p>
<a name="creating-the-main-page"></a>
<h2 id="creating-the-main-page">Creating the Main Page</h2>
<p>In the main.qml file, we use a <a href="../qtquick/qml-qtquick-rectangle.html">Rectangle</a> type within the <a href="qml-qtquick-controls-applicationwindow.html">ApplicationWindow</a> type to create the main page of the application:</p>
<pre class="qml"><span class="type"><a href="qml-qtquick-controls-applicationwindow.html">ApplicationWindow</a></span> {
<span class="name">visible</span>: <span class="number">true</span>
<span class="name">width</span>: <span class="number">800</span>
<span class="name">height</span>: <span class="number">1280</span>
<span class="type"><a href="../qtquick/qml-qtquick-rectangle.html">Rectangle</a></span> {
<span class="name">color</span>: <span class="string">"#212126"</span>
<span class="name">anchors</span>.fill: <span class="name">parent</span>
}</pre>
<p>To use the Qt Quick Controls, we must import them:</p>
<pre class="cpp">import <span class="type"><a href="../qtqml/qtquick-qmlmodule.html">QtQuick</a></span><span class="operator">.</span>Controls <span class="number">1.2</span></pre>
<p>The <code>toolBar</code> property of the application window holds a <a href="../qtquick/qtquick-imageelements-example.html#borderimage">BorderImage</a> type that we use to create a separator between the application name and a list of additional pages:</p>
<pre class="qml"> <span class="name">toolBar</span>: <span class="name">BorderImage</span> {
<span class="name">border</span>.bottom: <span class="number">8</span>
<span class="name">source</span>: <span class="string">"images/toolbar.png"</span>
<span class="name">width</span>: <span class="name">parent</span>.<span class="name">width</span>
<span class="name">height</span>: <span class="number">100</span></pre>
<p>We use an <a href="../qtquick/qtquick-imageelements-example.html#image">Image</a> type in a <a href="../qtquick/qml-qtquick-rectangle.html">Rectangle</a> type to create a back button. We use the <code>onClicked</code> signal handler to call the <a href="qml-qtquick-controls-stackview.html">StackView</a> <code>pop()</code> function that pops off the page when users tap the button:</p>
<pre class="qml"> <span class="type"><a href="../qtquick/qml-qtquick-rectangle.html">Rectangle</a></span> {
<span class="name">id</span>: <span class="name">backButton</span>
<span class="name">width</span>: <span class="name">opacity</span> ? <span class="number">60</span> : <span class="number">0</span>
<span class="name">anchors</span>.left: <span class="name">parent</span>.<span class="name">left</span>
<span class="name">anchors</span>.leftMargin: <span class="number">20</span>
<span class="name">opacity</span>: <span class="name">stackView</span>.<span class="name">depth</span> <span class="operator">></span> <span class="number">1</span> ? <span class="number">1</span> : <span class="number">0</span>
<span class="name">anchors</span>.verticalCenter: <span class="name">parent</span>.<span class="name">verticalCenter</span>
<span class="name">antialiasing</span>: <span class="number">true</span>
<span class="name">height</span>: <span class="number">60</span>
<span class="name">radius</span>: <span class="number">4</span>
<span class="name">color</span>: <span class="name">backmouse</span>.<span class="name">pressed</span> ? <span class="string">"#222"</span> : <span class="string">"transparent"</span>
Behavior on <span class="name">opacity</span> { <span class="type"><a href="../qtquick/qml-qtquick-numberanimation.html">NumberAnimation</a></span>{} }
<span class="type"><a href="../qtquick/qml-qtquick-image.html">Image</a></span> {
<span class="name">anchors</span>.verticalCenter: <span class="name">parent</span>.<span class="name">verticalCenter</span>
<span class="name">source</span>: <span class="string">"images/navigation_previous_item.png"</span>
}
<span class="type"><a href="../qtquick/qml-qtquick-mousearea.html">MouseArea</a></span> {
<span class="name">id</span>: <span class="name">backmouse</span>
<span class="name">anchors</span>.fill: <span class="name">parent</span>
<span class="name">anchors</span>.margins: -<span class="number">10</span>
<span class="name">onClicked</span>: <span class="name">stackView</span>.<span class="name">pop</span>()
}
}</pre>
<p>We use the <code>opacity</code> property to hide the back button on the main page.</p>
<p>We use a <a href="../qtquick/qml-qtquick-text.html">Text</a> type to display the application name:</p>
<pre class="qml"> <span class="type"><a href="../qtquick/qml-qtquick-text.html">Text</a></span> {
<span class="name">font</span>.pixelSize: <span class="number">42</span>
Behavior on <span class="name">x</span> { <span class="type"><a href="../qtquick/qml-qtquick-numberanimation.html">NumberAnimation</a></span>{ <span class="name">easing</span>.type: <span class="name">Easing</span>.<span class="name">OutCubic</span>} }
<span class="name">x</span>: <span class="name">backButton</span>.<span class="name">x</span> <span class="operator">+</span> <span class="name">backButton</span>.<span class="name">width</span> <span class="operator">+</span> <span class="number">20</span>
<span class="name">anchors</span>.verticalCenter: <span class="name">parent</span>.<span class="name">verticalCenter</span>
<span class="name">color</span>: <span class="string">"white"</span>
<span class="name">text</span>: <span class="string">"Widget Gallery"</span>
}</pre>
<p>The <code>x</code> position of the <a href="../qtquick/qml-qtquick-text.html">Text</a> type is bound to the position and width of the back button, and animated using a <a href="../qtquick/qml-qtquick-behavior.html">Behavior</a>.</p>
<p>We use a <a href="../qtqml/qml-qtqml-models-listmodel.html">ListModel</a> type that contains <a href="../qtqml/qml-qtqml-models-listelement.html">ListElement</a> definitions to define titles and source files for the other pages in the application:</p>
<pre class="qml"> <span class="type"><a href="../qtqml/qml-qtqml-models-listmodel.html">ListModel</a></span> {
<span class="name">id</span>: <span class="name">pageModel</span>
<span class="type"><a href="../qtqml/qml-qtqml-models-listelement.html">ListElement</a></span> {
<span class="name">title</span>: <span class="string">"Buttons"</span>
<span class="name">page</span>: <span class="string">"content/ButtonPage.qml"</span>
}
<span class="type"><a href="../qtqml/qml-qtqml-models-listelement.html">ListElement</a></span> {
<span class="name">title</span>: <span class="string">"Sliders"</span>
<span class="name">page</span>: <span class="string">"content/SliderPage.qml"</span>
}
<span class="type"><a href="../qtqml/qml-qtqml-models-listelement.html">ListElement</a></span> {
<span class="name">title</span>: <span class="string">"ProgressBar"</span>
<span class="name">page</span>: <span class="string">"content/ProgressBarPage.qml"</span>
}
<span class="type"><a href="../qtqml/qml-qtqml-models-listelement.html">ListElement</a></span> {
<span class="name">title</span>: <span class="string">"Tabs"</span>
<span class="name">page</span>: <span class="string">"content/TabBarPage.qml"</span>
}
<span class="type"><a href="../qtqml/qml-qtqml-models-listelement.html">ListElement</a></span> {
<span class="name">title</span>: <span class="string">"TextInput"</span>
<span class="name">page</span>: <span class="string">"content/TextInputPage.qml"</span>
}
<span class="type"><a href="../qtqml/qml-qtqml-models-listelement.html">ListElement</a></span> {
<span class="name">title</span>: <span class="string">"List"</span>
<span class="name">page</span>: <span class="string">"content/ListPage.qml"</span>
}
}</pre>
<a name="navigating-in-the-application"></a>
<h2 id="navigating-in-the-application">Navigating in the Application</h2>
<p>We implement a stack-based navigation model to link the application pages together. Items are pushed onto the stack as users navigate deeper into the application, and popped off again when they return to the main page.</p>
<p>In main.qml, we add a <a href="qml-qtquick-controls-stackview.html">StackView</a> type as a child of the application window:</p>
<pre class="qml"> <span class="type"><a href="qml-qtquick-controls-stackview.html">StackView</a></span> {
<span class="name">id</span>: <span class="name">stackView</span>
<span class="name">anchors</span>.fill: <span class="name">parent</span>
<span class="comment">// Implements back key navigation</span>
<span class="name">focus</span>: <span class="number">true</span>
<span class="name">Keys</span>.onReleased: <span class="keyword">if</span> (<span class="name">event</span>.<span class="name">key</span> <span class="operator">===</span> <span class="name">Qt</span>.<span class="name">Key_Back</span> <span class="operator">&&</span> <span class="name">stackView</span>.<span class="name">depth</span> <span class="operator">></span> <span class="number">1</span>) {
<span class="name">stackView</span>.<span class="name">pop</span>();
<span class="name">event</span>.<span class="name">accepted</span> <span class="operator">=</span> <span class="number">true</span>;
}</pre>
<p>The stack is used by invoking its navigation methods. To load the first item in the stack view, we assign it to <code>initialItem</code>:</p>
<pre class="qml"> <span class="name">initialItem</span>: <span class="name">Item</span> {
<span class="name">width</span>: <span class="name">parent</span>.<span class="name">width</span>
<span class="name">height</span>: <span class="name">parent</span>.<span class="name">height</span>
<span class="type"><a href="../qtquick/qml-qtquick-listview.html">ListView</a></span> {
<span class="name">model</span>: <span class="name">pageModel</span>
<span class="name">anchors</span>.fill: <span class="name">parent</span>
<span class="name">delegate</span>: <span class="name">AndroidDelegate</span> {
<span class="name">text</span>: <span class="name">title</span>
<span class="name">onClicked</span>: <span class="name">stackView</span>.<span class="name">push</span>(<span class="name">Qt</span>.<span class="name">resolvedUrl</span>(<span class="name">page</span>))
}
}
}
}
}</pre>
<p>We use a <a href="../qtquick/qml-qtquick-listview.html">ListView</a> type to display a list of the items provided by <code>pageModel</code>. The <code>AndroidDelegate</code> custom type defines each item instantiated by the view.</p>
<a name="creating-push-buttons-and-switches"></a>
<h2 id="creating-push-buttons-and-switches">Creating Push Buttons and Switches</h2>
<p>In ButtonPage.qml we use the <a href="qml-qtquick-controls-button.html">Button</a> type to create two buttons that change color when users tap them and one that pops off the page and returns the user to the main page:</p>
<pre class="qml"> <span class="type"><a href="qml-qtquick-controls-button.html">Button</a></span> {
<span class="name">text</span>: <span class="string">"Press me"</span>
<span class="name">style</span>: <span class="name">touchStyle</span>
}
<span class="type"><a href="qml-qtquick-controls-button.html">Button</a></span> {
<span class="name">style</span>: <span class="name">touchStyle</span>
<span class="name">text</span>: <span class="string">"Press me too"</span>
}
<span class="type"><a href="qml-qtquick-controls-button.html">Button</a></span> {
<span class="name">anchors</span>.margins: <span class="number">20</span>
<span class="name">style</span>: <span class="name">touchStyle</span>
<span class="name">text</span>: <span class="string">"Don't press me"</span>
<span class="name">onClicked</span>: <span class="keyword">if</span> (<span class="name">stackView</span>) <span class="name">stackView</span>.<span class="name">pop</span>()
}</pre>
<p>We use a <a href="qml-qtquick-controls-switch.html">Switch</a> type to create two switches that users can turn on and off. They are placed within a <a href="../qtquick/qtquick-positioning-layouts.html#row">Row</a> type to lay them out horizontally:</p>
<pre class="qml"> <span class="type"><a href="../qtquick/qml-qtquick-row.html">Row</a></span> {
<span class="name">spacing</span>: <span class="number">20</span>
<span class="type"><a href="qml-qtquick-controls-switch.html">Switch</a></span> {
<span class="name">style</span>: <span class="name">switchStyle</span>
}
<span class="type"><a href="qml-qtquick-controls-switch.html">Switch</a></span> {
<span class="name">style</span>: <span class="name">switchStyle</span>
}
}</pre>
<p>A <a href="qml-qtquick-controls-styles-buttonstyle.html">ButtonStyle</a> type creates a custom appearance for the buttons:</p>
<pre class="qml"> <span class="type"><a href="../qtqml/qml-qtqml-component.html">Component</a></span> {
<span class="name">id</span>: <span class="name">touchStyle</span>
<span class="type">ButtonStyle</span> {
<span class="name">panel</span>: <span class="name">Item</span> {
<span class="name">implicitHeight</span>: <span class="number">50</span>
<span class="name">implicitWidth</span>: <span class="number">320</span>
<span class="type"><a href="../qtquick/qml-qtquick-borderimage.html">BorderImage</a></span> {
<span class="name">anchors</span>.fill: <span class="name">parent</span>
<span class="name">antialiasing</span>: <span class="number">true</span>
<span class="name">border</span>.bottom: <span class="number">8</span>
<span class="name">border</span>.top: <span class="number">8</span>
<span class="name">border</span>.left: <span class="number">8</span>
<span class="name">border</span>.right: <span class="number">8</span>
<span class="name">anchors</span>.margins: <span class="name">control</span>.<span class="name">pressed</span> ? -<span class="number">4</span> : <span class="number">0</span>
<span class="name">source</span>: <span class="name">control</span>.<span class="name">pressed</span> ? <span class="string">"../images/button_pressed.png"</span> : <span class="string">"../images/button_default.png"</span>
<span class="type"><a href="../qtquick/qml-qtquick-text.html">Text</a></span> {
<span class="name">text</span>: <span class="name">control</span>.<span class="name">text</span>
<span class="name">anchors</span>.centerIn: <span class="name">parent</span>
<span class="name">color</span>: <span class="string">"white"</span>
<span class="name">font</span>.pixelSize: <span class="number">23</span>
<span class="name">renderType</span>: <span class="name">Text</span>.<span class="name">NativeRendering</span>
}</pre>
<p>To use Qt Quick Controls Styles, we must import them:</p>
<pre class="cpp">import <span class="type"><a href="../qtqml/qtquick-qmlmodule.html">QtQuick</a></span><span class="operator">.</span>Controls<span class="operator">.</span>Styles <span class="number">1.1</span></pre>
<p>A <a href="qml-qtquick-controls-styles-switchstyle.html">SwitchStyle</a> type creates a custom appearance for the switches:</p>
<pre class="qml"> <span class="type"><a href="../qtqml/qml-qtqml-component.html">Component</a></span> {
<span class="name">id</span>: <span class="name">switchStyle</span>
<span class="type">SwitchStyle</span> {
<span class="name">groove</span>: <span class="name">Rectangle</span> {
<span class="name">implicitHeight</span>: <span class="number">50</span>
<span class="name">implicitWidth</span>: <span class="number">152</span>
<span class="type"><a href="../qtquick/qml-qtquick-rectangle.html">Rectangle</a></span> {
<span class="name">anchors</span>.top: <span class="name">parent</span>.<span class="name">top</span>
<span class="name">anchors</span>.left: <span class="name">parent</span>.<span class="name">left</span>
<span class="name">anchors</span>.bottom: <span class="name">parent</span>.<span class="name">bottom</span>
<span class="name">width</span>: <span class="name">parent</span>.<span class="name">width</span><span class="operator">/</span><span class="number">2</span> <span class="operator">-</span> <span class="number">2</span>
<span class="name">height</span>: <span class="number">20</span>
<span class="name">anchors</span>.margins: <span class="number">2</span>
<span class="name">color</span>: <span class="name">control</span>.<span class="name">checked</span> ? <span class="string">"#468bb7"</span> : <span class="string">"#222"</span>
Behavior on <span class="name">color</span> {<span class="type"><a href="../qtquick/qml-qtquick-coloranimation.html">ColorAnimation</a></span> {}}
<span class="type"><a href="../qtquick/qml-qtquick-text.html">Text</a></span> {
<span class="name">font</span>.pixelSize: <span class="number">23</span>
<span class="name">color</span>: <span class="string">"white"</span>
<span class="name">anchors</span>.centerIn: <span class="name">parent</span>
<span class="name">text</span>: <span class="string">"ON"</span>
}
}
<span class="type"><a href="../qtquick/qml-qtquick-item.html">Item</a></span> {
<span class="name">width</span>: <span class="name">parent</span>.<span class="name">width</span><span class="operator">/</span><span class="number">2</span>
<span class="name">height</span>: <span class="name">parent</span>.<span class="name">height</span>
<span class="name">anchors</span>.right: <span class="name">parent</span>.<span class="name">right</span>
<span class="type"><a href="../qtquick/qml-qtquick-text.html">Text</a></span> {
<span class="name">font</span>.pixelSize: <span class="number">23</span>
<span class="name">color</span>: <span class="string">"white"</span>
<span class="name">anchors</span>.centerIn: <span class="name">parent</span>
<span class="name">text</span>: <span class="string">"OFF"</span>
}
}
<span class="name">color</span>: <span class="string">"#222"</span>
<span class="name">border</span>.color: <span class="string">"#444"</span>
<span class="name">border</span>.width: <span class="number">2</span>
}
<span class="name">handle</span>: <span class="name">Rectangle</span> {
<span class="name">width</span>: <span class="name">parent</span>.<span class="name">parent</span>.<span class="name">width</span><span class="operator">/</span><span class="number">2</span>
<span class="name">height</span>: <span class="name">control</span>.<span class="name">height</span>
<span class="name">color</span>: <span class="string">"#444"</span>
<span class="name">border</span>.color: <span class="string">"#555"</span>
<span class="name">border</span>.width: <span class="number">2</span>
}
}
}
}</pre>
<p>The <code>groove</code> property holds the background groove of the switch and the <code>handle</code> property defines the switch handle.</p>
<a name="creating-sliders"></a>
<h2 id="creating-sliders">Creating Sliders</h2>
<p>In SliderPage.qml, we use a <a href="qml-qtquick-controls-slider.html">Slider</a> type to create three horizontal sliders that are placed within a <a href="../qtquick/qtquick-positioning-layouts.html#column">Column</a> type to lay them out in a column:</p>
<pre class="qml"> <span class="type"><a href="../qtquick/qml-qtquick-column.html">Column</a></span> {
<span class="name">spacing</span>: <span class="number">12</span>
<span class="name">anchors</span>.centerIn: <span class="name">parent</span>
<span class="type"><a href="qml-qtquick-controls-slider.html">Slider</a></span> {
<span class="name">anchors</span>.margins: <span class="number">20</span>
<span class="name">style</span>: <span class="name">touchStyle</span>
<span class="name">value</span>: <span class="number">0</span>
}
<span class="type"><a href="qml-qtquick-controls-slider.html">Slider</a></span> {
<span class="name">anchors</span>.margins: <span class="number">20</span>
<span class="name">style</span>: <span class="name">touchStyle</span>
<span class="name">value</span>: <span class="number">0.5</span>
}
<span class="type"><a href="qml-qtquick-controls-slider.html">Slider</a></span> {
<span class="name">anchors</span>.margins: <span class="number">20</span>
<span class="name">style</span>: <span class="name">touchStyle</span>
<span class="name">value</span>: <span class="number">1.0</span>
}
}</pre>
<p>The <code>value</code> property holds the initial handle position on the slider.</p>
<p>A <a href="qml-qtquick-controls-styles-sliderstyle.html">SliderStyle</a> type creates a custom appearance for the sliders:</p>
<pre class="qml"> <span class="type"><a href="../qtqml/qml-qtqml-component.html">Component</a></span> {
<span class="name">id</span>: <span class="name">touchStyle</span>
<span class="type">SliderStyle</span> {
<span class="name">handle</span>: <span class="name">Rectangle</span> {
<span class="name">width</span>: <span class="number">30</span>
<span class="name">height</span>: <span class="number">30</span>
<span class="name">radius</span>: <span class="name">height</span>
<span class="name">antialiasing</span>: <span class="number">true</span>
<span class="name">color</span>: <span class="name">Qt</span>.<span class="name">lighter</span>(<span class="string">"#468bb7"</span>, <span class="number">1.2</span>)
}
<span class="name">groove</span>: <span class="name">Item</span> {
<span class="name">implicitHeight</span>: <span class="number">50</span>
<span class="name">implicitWidth</span>: <span class="number">400</span>
<span class="type"><a href="../qtquick/qml-qtquick-rectangle.html">Rectangle</a></span> {
<span class="name">height</span>: <span class="number">8</span>
<span class="name">width</span>: <span class="name">parent</span>.<span class="name">width</span>
<span class="name">anchors</span>.verticalCenter: <span class="name">parent</span>.<span class="name">verticalCenter</span>
<span class="name">color</span>: <span class="string">"#444"</span>
<span class="name">opacity</span>: <span class="number">0.8</span>
<span class="type"><a href="../qtquick/qml-qtquick-rectangle.html">Rectangle</a></span> {
<span class="name">antialiasing</span>: <span class="number">true</span>
<span class="name">radius</span>: <span class="number">1</span>
<span class="name">color</span>: <span class="string">"#468bb7"</span>
<span class="name">height</span>: <span class="name">parent</span>.<span class="name">height</span>
<span class="name">width</span>: <span class="name">parent</span>.<span class="name">width</span> <span class="operator">*</span> <span class="name">control</span>.<span class="name">value</span> <span class="operator">/</span> <span class="name">control</span>.<span class="name">maximumValue</span>
}
}
}
}
}
}</pre>
<p>The <code>handle</code> property defines the slider handle and the <code>groove</code> property holds the background groove of the slider.</p>
<a name="indicating-progress"></a>
<h2 id="indicating-progress">Indicating Progress</h2>
<p>In <a href="qml-qtquick-controls-progressbar.html">ProgressBar</a>.qml, we use a <a href="qml-qtquick-controls-progressbar.html">ProgressBar</a> type to create three progress bars:</p>
<pre class="qml"> <span class="type"><a href="../qtquick/qml-qtquick-column.html">Column</a></span> {
<span class="name">spacing</span>: <span class="number">40</span>
<span class="name">anchors</span>.centerIn: <span class="name">parent</span>
<span class="type"><a href="qml-qtquick-controls-progressbar.html">ProgressBar</a></span> {
<span class="name">anchors</span>.margins: <span class="number">20</span>
<span class="name">style</span>: <span class="name">touchStyle</span>
<span class="name">width</span>: <span class="number">400</span>
<span class="name">value</span>: <span class="name">progress</span>
}
<span class="type"><a href="qml-qtquick-controls-progressbar.html">ProgressBar</a></span> {
<span class="name">anchors</span>.margins: <span class="number">20</span>
<span class="name">style</span>: <span class="name">touchStyle</span>
<span class="name">width</span>: <span class="number">400</span>
<span class="name">value</span>: <span class="number">1</span> <span class="operator">-</span> <span class="name">progress</span>
}
<span class="type"><a href="qml-qtquick-controls-progressbar.html">ProgressBar</a></span> {
<span class="name">anchors</span>.margins: <span class="number">20</span>
<span class="name">style</span>: <span class="name">touchStyle</span>
<span class="name">value</span>: <span class="number">1</span>
<span class="name">width</span>: <span class="number">400</span>
}</pre>
<p>We use a <a href="../qtquick/qml-qtquick-numberanimation.html">NumberAnimation</a> type with a <a href="../qtquick/qml-qtquick-sequentialanimation.html">SequentialAnimation</a> type to run two number animations in a sequence. We apply the animations on the <code>progress</code> custom property to animate the current value on the progress bars:</p>
<pre class="qml"> property <span class="type">real</span> <span class="name">progress</span>: <span class="number">0</span>
SequentialAnimation on <span class="name">progress</span> {
<span class="name">loops</span>: <span class="name">Animation</span>.<span class="name">Infinite</span>
<span class="name">running</span>: <span class="number">true</span>
<span class="type"><a href="../qtquick/qml-qtquick-numberanimation.html">NumberAnimation</a></span> {
<span class="name">from</span>: <span class="number">0</span>
<span class="name">to</span>: <span class="number">1</span>
<span class="name">duration</span>: <span class="number">3000</span>
}
<span class="type"><a href="../qtquick/qml-qtquick-numberanimation.html">NumberAnimation</a></span> {
<span class="name">from</span>: <span class="number">1</span>
<span class="name">to</span>: <span class="number">0</span>
<span class="name">duration</span>: <span class="number">3000</span>
}</pre>
<p>A <a href="qml-qtquick-controls-styles-progressbarstyle.html">ProgressBarStyle</a> type creates a custom appearance for the progress bars:</p>
<pre class="qml"> <span class="type"><a href="../qtqml/qml-qtqml-component.html">Component</a></span> {
<span class="name">id</span>: <span class="name">touchStyle</span>
<span class="type">ProgressBarStyle</span> {
<span class="name">panel</span>: <span class="name">Rectangle</span> {
<span class="name">implicitHeight</span>: <span class="number">15</span>
<span class="name">implicitWidth</span>: <span class="number">400</span>
<span class="name">color</span>: <span class="string">"#444"</span>
<span class="name">opacity</span>: <span class="number">0.8</span>
<span class="type"><a href="../qtquick/qml-qtquick-rectangle.html">Rectangle</a></span> {
<span class="name">antialiasing</span>: <span class="number">true</span>
<span class="name">radius</span>: <span class="number">1</span>
<span class="name">color</span>: <span class="string">"#468bb7"</span>
<span class="name">height</span>: <span class="name">parent</span>.<span class="name">height</span>
<span class="name">width</span>: <span class="name">parent</span>.<span class="name">width</span> <span class="operator">*</span> <span class="name">control</span>.<span class="name">value</span> <span class="operator">/</span> <span class="name">control</span>.<span class="name">maximumValue</span>
}
}
}
}
}</pre>
<a name="creating-tabs"></a>
<h2 id="creating-tabs">Creating Tabs</h2>
<p>In TabBarPage.qml, we use a <a href="qml-qtquick-controls-tabview.html">TabView</a> type with a <a href="qml-qtquick-controls-tab.html">Tab</a> type to provide a tab-based navigation model for our application. We use tabs to display the ButtonPage, SliderPage, and ProgressBarPage on separate tab pages:</p>
<pre class="qml"> <span class="type"><a href="qml-qtquick-controls-tabview.html">TabView</a></span> {
<span class="name">anchors</span>.fill: <span class="name">parent</span>
<span class="name">style</span>: <span class="name">touchStyle</span>
<span class="type"><a href="qml-qtquick-controls-tab.html">Tab</a></span> {
<span class="name">title</span>: <span class="string">"Buttons"</span>
<span class="type">ButtonPage</span>{ <span class="name">visible</span>: <span class="number">true</span> }
}
<span class="type"><a href="qml-qtquick-controls-tab.html">Tab</a></span> {
<span class="name">title</span>: <span class="string">"Sliders"</span>
<span class="type">SliderPage</span>{ <span class="name">visible</span>: <span class="number">true</span> }
}
<span class="type"><a href="qml-qtquick-controls-tab.html">Tab</a></span> {
<span class="name">title</span>: <span class="string">"Progress"</span>
<span class="type">ProgressBarPage</span>{ <span class="name">visible</span>: <span class="number">true</span> }
}</pre>
<p>A <a href="qml-qtquick-controls-styles-tabviewstyle.html">TabViewStyle</a> type creates a custom appearance for the tabs:</p>
<pre class="qml"> <span class="type"><a href="../qtqml/qml-qtqml-component.html">Component</a></span> {
<span class="name">id</span>: <span class="name">touchStyle</span>
<span class="type">TabViewStyle</span> {
<span class="name">tabsAlignment</span>: <span class="name">Qt</span>.<span class="name">AlignVCenter</span>
<span class="name">tabOverlap</span>: <span class="number">0</span>
<span class="name">frame</span>: <span class="name">Item</span> { }
<span class="name">tab</span>: <span class="name">Item</span> {
<span class="name">implicitWidth</span>: <span class="name">control</span>.<span class="name">width</span><span class="operator">/</span><span class="name">control</span>.<span class="name">count</span>
<span class="name">implicitHeight</span>: <span class="number">50</span>
<span class="type"><a href="../qtquick/qml-qtquick-borderimage.html">BorderImage</a></span> {
<span class="name">anchors</span>.fill: <span class="name">parent</span>
<span class="name">border</span>.bottom: <span class="number">8</span>
<span class="name">border</span>.top: <span class="number">8</span>
<span class="name">source</span>: <span class="name">styleData</span>.<span class="name">selected</span> ? <span class="string">"../images/tab_selected.png"</span>:<span class="string">"../images/tabs_standard.png"</span>
<span class="type"><a href="../qtquick/qml-qtquick-text.html">Text</a></span> {
<span class="name">anchors</span>.centerIn: <span class="name">parent</span>
<span class="name">color</span>: <span class="string">"white"</span>
<span class="name">text</span>: <span class="name">styleData</span>.<span class="name">title</span>.<span class="name">toUpperCase</span>()
<span class="name">font</span>.pixelSize: <span class="number">16</span>
}
<span class="type"><a href="../qtquick/qml-qtquick-rectangle.html">Rectangle</a></span> {
<span class="name">visible</span>: <span class="name">index</span> <span class="operator">></span> <span class="number">0</span>
<span class="name">anchors</span>.top: <span class="name">parent</span>.<span class="name">top</span>
<span class="name">anchors</span>.bottom: <span class="name">parent</span>.<span class="name">bottom</span>
<span class="name">anchors</span>.margins: <span class="number">10</span>
<span class="name">width</span>:<span class="number">1</span>
<span class="name">color</span>: <span class="string">"#3a3a3a"</span>
}
}
}
}
}
}</pre>
<a name="creating-text-input-fields"></a>
<h2 id="creating-text-input-fields">Creating Text Input Fields</h2>
<p>In the TextInputPage.qml, we use a <a href="qml-qtquick-controls-textfield.html">TextField</a> type to create an input field and a read-only text field:</p>
<pre class="qml"> <span class="type"><a href="../qtquick/qml-qtquick-column.html">Column</a></span> {
<span class="name">spacing</span>: <span class="number">40</span>
<span class="name">anchors</span>.centerIn: <span class="name">parent</span>
<span class="type"><a href="qml-qtquick-controls-textfield.html">TextField</a></span> {
<span class="name">anchors</span>.margins: <span class="number">20</span>
<span class="name">text</span>: <span class="string">"Text input"</span>
<span class="name">style</span>: <span class="name">touchStyle</span>
}
<span class="type"><a href="qml-qtquick-controls-textfield.html">TextField</a></span> {
<span class="name">anchors</span>.margins: <span class="number">20</span>
<span class="name">text</span>: <span class="string">"Readonly Text input"</span>
<span class="name">style</span>: <span class="name">touchStyle</span>
<span class="name">readOnly</span>: <span class="number">true</span>
}
}</pre>
<p>A <a href="qml-qtquick-controls-styles-textfieldstyle.html">TextFieldStyle</a> creates a custom appearance for the text fields:</p>
<pre class="qml"> <span class="type"><a href="../qtqml/qml-qtqml-component.html">Component</a></span> {
<span class="name">id</span>: <span class="name">touchStyle</span>
<span class="type">TextFieldStyle</span> {
<span class="name">textColor</span>: <span class="string">"white"</span>
<span class="name">font</span>.pixelSize: <span class="number">28</span>
<span class="name">background</span>: <span class="name">Item</span> {
<span class="name">implicitHeight</span>: <span class="number">50</span>
<span class="name">implicitWidth</span>: <span class="number">320</span>
<span class="type"><a href="../qtquick/qml-qtquick-borderimage.html">BorderImage</a></span> {
<span class="name">source</span>: <span class="string">"../images/textinput.png"</span>
<span class="name">border</span>.left: <span class="number">8</span>
<span class="name">border</span>.right: <span class="number">8</span>
<span class="name">anchors</span>.bottom: <span class="name">parent</span>.<span class="name">bottom</span>
<span class="name">anchors</span>.left: <span class="name">parent</span>.<span class="name">left</span>
<span class="name">anchors</span>.right: <span class="name">parent</span>.<span class="name">right</span>
}
}
}
}
}</pre>
<p>We use a <a href="../qtquick/qtquick-imageelements-example.html#borderimage">BorderImage</a> type with an image to create borders for the fields.</p>
<a name="creating-scrolling-lists"></a>
<h2 id="creating-scrolling-lists">Creating Scrolling Lists</h2>
<p>In ListPage.qml, we use a <a href="qml-qtquick-controls-scrollview.html">ScrollView</a> type to provide a scrolling page with a vertical scoll bar:</p>
<pre class="qml"><span class="type"><a href="qml-qtquick-controls-scrollview.html">ScrollView</a></span> {
<span class="name">width</span>: <span class="name">parent</span>.<span class="name">width</span>
<span class="name">height</span>: <span class="name">parent</span>.<span class="name">height</span>
<span class="name">flickableItem</span>.interactive: <span class="number">true</span></pre>
<p>We use a <a href="../qtquick/qml-qtquick-listview.html">ListView</a> type to display a list of 100 items by specifying an <a href="../qtquick/qtquick-modelviewsdata-modelview.html#integers-as-models">integer</a> as the value of the <code>model</code> property. We reuse the <code>AndroidDelegate</code> custom type here to define each item instantiated by the view. The <code>text</code> property adds the string <code>Item #</code> to each list item:</p>
<pre class="qml"> <span class="type"><a href="../qtquick/qml-qtquick-listview.html">ListView</a></span> {
<span class="name">anchors</span>.fill: <span class="name">parent</span>
<span class="name">model</span>: <span class="number">100</span>
<span class="name">delegate</span>: <span class="name">AndroidDelegate</span> {
<span class="name">text</span>: <span class="string">"Item #"</span> <span class="operator">+</span> <span class="name">modelData</span>
}
}</pre>
<p>A <a href="qml-qtquick-controls-styles-scrollviewstyle.html">ScrollViewStyle</a> type creates a custom appearance for the scroll view:</p>
<pre class="qml"> <span class="name">style</span>: <span class="name">ScrollViewStyle</span> {
<span class="name">transientScrollBars</span>: <span class="number">true</span>
<span class="name">handle</span>: <span class="name">Item</span> {
<span class="name">implicitWidth</span>: <span class="number">14</span>
<span class="name">implicitHeight</span>: <span class="number">26</span>
<span class="type"><a href="../qtquick/qml-qtquick-rectangle.html">Rectangle</a></span> {
<span class="name">color</span>: <span class="string">"#424246"</span>
<span class="name">anchors</span>.fill: <span class="name">parent</span>
<span class="name">anchors</span>.topMargin: <span class="number">6</span>
<span class="name">anchors</span>.leftMargin: <span class="number">4</span>
<span class="name">anchors</span>.rightMargin: <span class="number">4</span>
<span class="name">anchors</span>.bottomMargin: <span class="number">6</span>
}
}
<span class="name">scrollBarBackground</span>: <span class="name">Item</span> {
<span class="name">implicitWidth</span>: <span class="number">14</span>
<span class="name">implicitHeight</span>: <span class="number">26</span>
}
}
}</pre>
<p>The <code>transientScrollBars</code> property is set to <code>true</code> to make the scroll bars appear when the content is scrolled and disappear when they are no longer needed.</p>
<p>The <code>handle</code> property controls the appearance of the scroll bar handle and the <code>scrollBarBackground</code> property that of the background.</p>
<p>Files:</p>
<ul>
<li><a href="qtquickcontrols-touch-main-qml.html">touch/main.qml</a></li>
<li><a href="qtquickcontrols-touch-content-androiddelegate-qml.html">touch/content/AndroidDelegate.qml</a></li>
<li><a href="qtquickcontrols-touch-content-buttonpage-qml.html">touch/content/ButtonPage.qml</a></li>
<li><a href="qtquickcontrols-touch-content-listpage-qml.html">touch/content/ListPage.qml</a></li>
<li><a href="qtquickcontrols-touch-content-progressbarpage-qml.html">touch/content/ProgressBarPage.qml</a></li>
<li><a href="qtquickcontrols-touch-content-sliderpage-qml.html">touch/content/SliderPage.qml</a></li>
<li><a href="qtquickcontrols-touch-content-tabbarpage-qml.html">touch/content/TabBarPage.qml</a></li>
<li><a href="qtquickcontrols-touch-content-textinputpage-qml.html">touch/content/TextInputPage.qml</a></li>
<li><a href="qtquickcontrols-touch-src-main-cpp.html">touch/src/main.cpp</a></li>
<li><a href="qtquickcontrols-touch-resources-qrc.html">touch/resources.qrc</a></li>
<li><a href="qtquickcontrols-touch-touch-pro.html">touch/touch.pro</a></li>
<li><a href="qtquickcontrols-touch-touch-qmlproject.html">touch/touch.qmlproject</a></li>
</ul>
<p>Images:</p>
<ul>
<li><a href="images/used-in-examples/touch/images/button_default.png">touch/images/button_default.png</a></li>
<li><a href="images/used-in-examples/touch/images/button_pressed.png">touch/images/button_pressed.png</a></li>
<li><a href="images/used-in-examples/touch/images/navigation_next_item.png">touch/images/navigation_next_item.png</a></li>
<li><a href="images/used-in-examples/touch/images/navigation_previous_item.png">touch/images/navigation_previous_item.png</a></li>
<li><a href="images/used-in-examples/touch/images/tab_selected.png">touch/images/tab_selected.png</a></li>
<li><a href="images/used-in-examples/touch/images/tabs_standard.png">touch/images/tabs_standard.png</a></li>
<li><a href="images/used-in-examples/touch/images/textinput.png">touch/images/textinput.png</a></li>
<li><a href="images/used-in-examples/touch/images/toolbar.png">touch/images/toolbar.png</a></li>
</ul>
</div>
<!-- @@@touch -->
</div>
</div>
</div>
</div>
</div>
<div class="footer">
<p>
<acronym title="Copyright">©</acronym> 2015 The Qt Company Ltd.
Documentation contributions included herein are the copyrights of
their respective owners.<br> The documentation provided herein is licensed under the terms of the <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation License version 1.3</a> as published by the Free Software Foundation.<br> Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property
of their respective owners. </p>
</div>
</body>
</html>
|