/usr/share/qt5/doc/qtquickcontrols/qtquickcontrols-calendar-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 | <?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 - Calendar Example | 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 - Calendar Example</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>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Qt Quick Controls - Calendar Example</h1>
<span class="subtitle"></span>
<!-- $$$calendar-description -->
<div class="descr"> <a name="details"></a>
<p class="centerAlign"><img src="images/qtquickcontrols-example-calendar.png" alt="" /></p><p>The Calendar example displays a Calendar control and an events list for the selected date. It uses a C++ class to fetch the event details from an SQLite database. The example app uses a custom <a href="qml-qtquick-controls-styles-calendarstyle.html">CalendarStyle</a> to highlight the selected date and mark the dates that have events.</p>
<p>The following snippet from <i>main.qml</i> shows how the Calendar control is used in the app:</p>
<pre class="cpp">Calendar {
id: calendar
width: (parent<span class="operator">.</span>width <span class="operator">></span> parent<span class="operator">.</span>height <span class="operator">?</span> parent<span class="operator">.</span>width <span class="operator">*</span> <span class="number">0.6</span> <span class="operator">-</span> parent<span class="operator">.</span>spacing : parent<span class="operator">.</span>width)
height: (parent<span class="operator">.</span>height <span class="operator">></span> parent<span class="operator">.</span>width <span class="operator">?</span> parent<span class="operator">.</span>height <span class="operator">*</span> <span class="number">0.6</span> <span class="operator">-</span> parent<span class="operator">.</span>spacing : parent<span class="operator">.</span>height)
frameVisible: <span class="keyword">true</span>
weekNumbersVisible: <span class="keyword">true</span>
selectedDate: <span class="keyword">new</span> Date(<span class="number">2014</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">1</span>)
focus: <span class="keyword">true</span>
style: CalendarStyle {
dayDelegate: Item {
<span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
}
}
}</pre>
<p>The C++ class, SqlEventModel, inherits SqlQueryModel to create a database with dummy events for certain dates.</p>
<pre class="qml">SqlEventModel<span class="operator">::</span>SqlEventModel() :
<span class="type">QSqlQueryModel</span>()
{
createConnection();
}
<span class="type">void</span> SqlEventModel<span class="operator">::</span>createConnection()
{
<span class="type">QSqlDatabase</span> db <span class="operator">=</span> <span class="type">QSqlDatabase</span><span class="operator">::</span>addDatabase(<span class="string">"QSQLITE"</span>);
db<span class="operator">.</span>setDatabaseName(<span class="string">":memory:"</span>);
<span class="keyword">if</span> (<span class="operator">!</span>db<span class="operator">.</span>open()) {
<a href="../qtcore/qtglobal.html#qFatal">qFatal</a>(<span class="string">"Cannot open database"</span>);
<span class="keyword">return</span>;
}
<span class="type">QSqlQuery</span> query;
<span class="comment">// We store the time as seconds because it's easier to query.</span>
query<span class="operator">.</span>exec(<span class="string">"create table Event (name TEXT, startDate DATE, startTime INT, endDate DATE, endTime INT)"</span>);
query<span class="operator">.</span>exec(<span class="string">"insert into Event values('Grocery shopping', '2014-01-01', 36000, '2014-01-01', 39600)"</span>);
query<span class="operator">.</span>exec(<span class="string">"insert into Event values('Ice skating', '2014-01-01', 57600, '2014-01-01', 61200)"</span>);
query<span class="operator">.</span>exec(<span class="string">"insert into Event values('Doctor''s appointment', '2014-01-15', 57600, '2014-01-15', 63000)"</span>);
query<span class="operator">.</span>exec(<span class="string">"insert into Event values('Conference', '2014-01-24', 32400, '2014-01-28', 61200)"</span>);
<span class="keyword">return</span>;
}</pre>
<p>In <i>main.qml</i>, the SqlEventModel custom type is used to get the list of events to mark the dates on the calendar.</p>
<pre class="cpp">SqlEventModel {
id: eventModel
}
Calendar {
<span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
style: CalendarStyle {
dayDelegate: Item {
<span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
Image {
visible: eventModel<span class="operator">.</span>eventsForDate(styleData<span class="operator">.</span>date)<span class="operator">.</span>length <span class="operator">></span> <span class="number">0</span>
<span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
source: <span class="string">"qrc:/images/eventindicator.png"</span>
}
}
}
}</pre>
<p>The app uses a Flow type to position the items, and manipulates the items' width and height based on the orientation change on mobile devices.</p>
<pre class="cpp">Calendar {
id: calendar
width: (parent<span class="operator">.</span>width <span class="operator">></span> parent<span class="operator">.</span>height <span class="operator">?</span> parent<span class="operator">.</span>width <span class="operator">*</span> <span class="number">0.6</span> <span class="operator">-</span> parent<span class="operator">.</span>spacing : parent<span class="operator">.</span>width)
height: (parent<span class="operator">.</span>height <span class="operator">></span> parent<span class="operator">.</span>width <span class="operator">?</span> parent<span class="operator">.</span>height <span class="operator">*</span> <span class="number">0.6</span> <span class="operator">-</span> parent<span class="operator">.</span>spacing : parent<span class="operator">.</span>height)
}
Rectangle {
width: (parent<span class="operator">.</span>width <span class="operator">></span> parent<span class="operator">.</span>height <span class="operator">?</span> parent<span class="operator">.</span>width <span class="operator">*</span> <span class="number">0.4</span> <span class="operator">-</span> parent<span class="operator">.</span>spacing : parent<span class="operator">.</span>width)
height: (parent<span class="operator">.</span>height <span class="operator">></span> parent<span class="operator">.</span>width <span class="operator">?</span> parent<span class="operator">.</span>height <span class="operator">*</span> <span class="number">0.4</span> <span class="operator">-</span> parent<span class="operator">.</span>spacing : parent<span class="operator">.</span>height)
border<span class="operator">.</span>color: <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">.</span>darker(color<span class="operator">,</span> <span class="number">1.2</span>)
ListView {
<span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
}
}</pre>
<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>
<p>Files:</p>
<ul>
<li><a href="qtquickcontrols-calendar-qml-main-qml.html">calendar/qml/main.qml</a></li>
<li><a href="qtquickcontrols-calendar-src-event-cpp.html">calendar/src/event.cpp</a></li>
<li><a href="qtquickcontrols-calendar-src-event-h.html">calendar/src/event.h</a></li>
<li><a href="qtquickcontrols-calendar-src-sqleventmodel-cpp.html">calendar/src/sqleventmodel.cpp</a></li>
<li><a href="qtquickcontrols-calendar-src-sqleventmodel-h.html">calendar/src/sqleventmodel.h</a></li>
<li><a href="qtquickcontrols-calendar-src-main-cpp.html">calendar/src/main.cpp</a></li>
<li><a href="qtquickcontrols-calendar-calendar-pro.html">calendar/calendar.pro</a></li>
<li><a href="qtquickcontrols-calendar-resources-qrc.html">calendar/resources.qrc</a></li>
</ul>
<p>Images:</p>
<ul>
<li><a href="images/used-in-examples/calendar/images/eventindicator.png">calendar/images/eventindicator.png</a></li>
</ul>
</div>
<!-- @@@calendar -->
</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>
|