1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of the documentation of Qt for Python. 7 ** 8 ** $QT_BEGIN_LICENSE:BSD$ 9 ** Commercial License Usage 10 ** Licensees holding valid commercial Qt licenses may use this file in 11 ** accordance with the commercial license agreement provided with the 12 ** Software or, alternatively, in accordance with the terms contained in 13 ** a written agreement between you and The Qt Company. For licensing terms 14 ** and conditions see https://www.qt.io/terms-conditions. For further 15 ** information use the contact form at https://www.qt.io/contact-us. 16 ** 17 ** BSD License Usage 18 ** Alternatively, you may use this file under the terms of the BSD license 19 ** as follows: 20 ** 21 ** "Redistribution and use in source and binary forms, with or without 22 ** modification, are permitted provided that the following conditions are 23 ** met: 24 ** * Redistributions of source code must retain the above copyright 25 ** notice, this list of conditions and the following disclaimer. 26 ** * Redistributions in binary form must reproduce the above copyright 27 ** notice, this list of conditions and the following disclaimer in 28 ** the documentation and/or other materials provided with the 29 ** distribution. 30 ** * Neither the name of The Qt Company Ltd nor the names of its 31 ** contributors may be used to endorse or promote products derived 32 ** from this software without specific prior written permission. 33 ** 34 ** 35 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 36 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 37 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 38 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 39 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 42 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 43 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 45 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 46 ** 47 ** $QT_END_LICENSE$ 48 ** 49 ****************************************************************************/ 50 51 //! [0] 52 settings = QSettings("MySoft", "Star Runner") 53 color = QColor(settings.value("DataPump/bgcolor")) 54 //! [0] 55 56 57 //! [1] 58 settings = QSettings("MySoft", "Star Runner") 59 color = palette().background().color() 60 settings.setValue("DataPump/bgcolor", color) 61 //! [1] 62 63 64 //! [2] 65 settings = QSettings("/home/petra/misc/myapp.ini", 66 QSettings.IniFormat) 67 //! [2] 68 69 70 //! [3] 71 settings = QSettings("/Users/petra/misc/myapp.plist", 72 QSettings.NativeFormat) 73 //! [3] 74 75 76 //! [4] 77 settings = QSettings("HKEY_CURRENT_USER\\Software\\Microsoft\\Office", 78 QSettings.NativeFormat) 79 //! [4] 80 81 82 //! [5] 83 settings.setValue("11.0/Outlook/Security/DontTrustInstalledFiles", 0) 84 //! [5] 85 86 87 //! [6] 88 settings.setValue("HKEY_CURRENT_USER\\MySoft\\Star Runner\\Galaxy", "Milkyway") 89 settings.setValue("HKEY_CURRENT_USER\\MySoft\\Star Runner\\Galaxy\\Sun", "OurStar") 90 settings.value("HKEY_CURRENT_USER\\MySoft\\Star Runner\\Galaxy\\Default") # returns "Milkyway" 91 //! [6] 92 93 94 //! [7] 95 organizationName = "grenoullelogique.fr" if sys.platform.startswith('darwin') else "Grenoulle Logique" 96 settings = QSettings(organizationName, "Squash") 97 //! [7] 98 99 100 //! [8] 101 pos = @Point(100 100) 102 //! [8] 103 104 105 //! [9] 106 windir = C:\Windows 107 //! [9] 108 109 110 //! [10] 111 settings = QSettings("Moose Tech", "Facturo-Pro") 112 //! [10] 113 114 115 //! [11] 116 settings = QSettings("Moose Soft", "Facturo-Pro") 117 //! [11] 118 119 120 //! [12] 121 QCoreApplication.setOrganizationName("Moose Soft") 122 QCoreApplication.setApplicationName("Facturo-Pro") 123 settings = QSettings() 124 //! [12] 125 126 127 //! [13] 128 settings.beginGroup("mainwindow") 129 settings.setValue("size", win.size()) 130 settings.setValue("fullScreen", win.isFullScreen()) 131 settings.endGroup() 132 133 settings.beginGroup("outputpanel") 134 settings.setValue("visible", panel.isVisible()) 135 settings.endGroup() 136 //! [13] 137 138 139 //! [14] 140 settings.beginGroup("alpha") 141 # settings.group() == "alpha" 142 143 settings.beginGroup("beta") 144 # settings.group() == "alpha/beta" 145 146 settings.endGroup() 147 # settings.group() == "alpha" 148 149 settings.endGroup() 150 # settings.group() == "" 151 //! [14] 152 153 154 //! [15] 155 class Login: 156 userName = '' 157 password = '' 158 159 logins = [] 160 ... 161 162 settings = QSettings() 163 size = settings.beginReadArray("logins") 164 for i in range(size): 165 settings.setArrayIndex(i) 166 login = Login() 167 login.userName = settings.value("userName") 168 login.password = settings.value("password") 169 logins.append(login) 170 171 settings.endArray() 172 //! [15] 173 174 175 //! [16] 176 class Login: 177 userName = '' 178 password = '' 179 180 logins = [] 181 ... 182 183 settings = QSettings() 184 settings.beginWriteArray("logins") 185 for i in range(logins.size()): 186 settings.setArrayIndex(i) 187 settings.setValue("userName", list.at(i).userName) 188 settings.setValue("password", list.at(i).password) 189 190 settings.endArray() 191 //! [16] 192 193 194 //! [17] 195 settings = QSettings() 196 settings.setValue("fridge/color", Qt.white) 197 settings.setValue("fridge/size", QSize(32, 96)) 198 settings.setValue("sofa", True) 199 settings.setValue("tv", False) 200 201 keys = settings.allKeys(); 202 # keys: ["fridge/color", "fridge/size", "sofa", "tv"] 203 //! [17] 204 205 206 //! [18] 207 settings.beginGroup("fridge") 208 keys = settings.allKeys() 209 # keys: ["color", "size"] 210 //! [18] 211 212 213 //! [19] 214 settings = QSettings() 215 settings.setValue("fridge/color", Qt.white) 216 settings.setValue("fridge/size", QSize(32, 96)) 217 settings.setValue("sofa", True) 218 settings.setValue("tv", False) 219 220 keys = settings.childKeys() 221 # keys: ["sofa", "tv"] 222 //! [19] 223 224 225 //! [20] 226 settings.beginGroup("fridge") 227 keys = settings.childKeys() 228 # keys: ["color", "size"] 229 //! [20] 230 231 232 //! [21] 233 settings = QSettings() 234 settings.setValue("fridge/color", Qt.white) 235 settings.setValue("fridge/size", QSize(32, 96)); 236 settings.setValue("sofa", True) 237 settings.setValue("tv", False) 238 239 groups = settings.childGroups() 240 # group: ["fridge"] 241 //! [21] 242 243 244 //! [22] 245 settings.beginGroup("fridge") 246 groups = settings.childGroups() 247 # groups: [] 248 //! [22] 249 250 251 //! [23] 252 settings = QSettings() 253 settings.setValue("interval", 30) 254 settings.value("interval") # returns 30 255 256 settings.setValue("interval", 6.55) 257 settings.value("interval") # returns 6.55 258 //! [23] 259 260 261 //! [24] 262 settings = QSettings() 263 settings.setValue("ape") 264 settings.setValue("monkey", 1) 265 settings.setValue("monkey/sea", 2) 266 settings.setValue("monkey/doe", 4) 267 268 settings.remove("monkey") 269 keys = settings.allKeys() 270 # keys: ["ape"] 271 //! [24] 272 273 274 //! [25] 275 settings = QSettings() 276 settings.setValue("ape") 277 settings.setValue("monkey", 1) 278 settings.setValue("monkey/sea", 2) 279 settings.setValue("monkey/doe", 4) 280 281 settings.beginGroup("monkey") 282 settings.remove("") 283 settings.endGroup() 284 285 keys = settings.allKeys() 286 # keys: ["ape"] 287 //! [25] 288 289 290 //! [26] 291 settings = QSettings() 292 settings.setValue("animal/snake", 58) 293 settings.value("animal/snake", 1024) # returns 58 294 settings.value("animal/zebra", 1024) # returns 1024 295 settings.value("animal/zebra") # returns 0 296 //! [26] 297 298 299 //! [27] 300 # @arg device QIODevice 301 # @arg map QSettings.SettingsMap 302 # @return bool 303 def myReadFunc(device, map): 304 //! [27] 305 306 307 //! [28] 308 # @arg device QIODevice 309 # @arg map QSettings.SettingsMap 310 # @return bool 311 def myWriteFunc(device, map) 312 //! [28] 313 314 315 //! [29] 316 # @arg device QIODevice 317 # @arg map QSettings.SettingsMap 318 # @return bool 319 def readXmlFile(device, map): 320 def writeXmlFile(device, map): 321 322 def main(): 323 XmlFormat = QSettings::registerFormat("xml", readXmlFile, writeXmlFile) 324 settings = QSettings(XmlFormat, QSettings.UserSettings, 325 "MySoft", "Star Runner") 326 ... 327 //! [29] 328