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 examples 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 51from PySide2.QtGui import * 52 53//! [0] 54def __init__(self): 55 createSpinBoxes() 56 createDateTimeEdits() 57 createDoubleSpinBoxes() 58 59 layout = QHBoxLayout() 60 layout.addWidget(spinBoxesGroup) 61 layout.addWidget(editsGroup) 62 layout.addWidget(doubleSpinBoxesGroup) 63 setLayout(layout) 64 65 setWindowTitle(tr("Spin Boxes")) 66//! [0] 67 68//! [1] 69def createSpinBoxes(self): 70 spinBoxesGroup = QGroupBox(tr("Spinboxes")) 71 72 integerLabel = QLabel(tr("Enter a value between " 73 "%1 and %2:").arg(-20).arg(20)) 74 integerSpinBox = QSpinBox() 75 integerSpinBox.setRange(-20, 20) 76 integerSpinBox.setSingleStep(1) 77 integerSpinBox.setValue(0) 78//! [1] 79 80//! [2] 81 zoomLabel = QLabel(tr("Enter a zoom value between " 82 "%1 and %2:").arg(0).arg(1000)) 83//! [3] 84 zoomSpinBox = QSpinBox() 85 zoomSpinBox.setRange(0, 1000) 86 zoomSpinBox.setSingleStep(10) 87 zoomSpinBox.setSuffix("%") 88 zoomSpinBox.setSpecialValueText(tr("Automatic")) 89 zoomSpinBox.setValue(100) 90//! [2] //! [3] 91 92//! [4] 93 priceLabel = QLabel(tr("Enter a price between " 94 "%1 and %2:").arg(0).arg(999)) 95 priceSpinBox = QSpinBox() 96 priceSpinBox.setRange(0, 999) 97 priceSpinBox.setSingleStep(1) 98 priceSpinBox.setPrefix("$") 99 priceSpinBox.setValue(99) 100//! [4] //! [5] 101 102 spinBoxLayout = QVBoxLayout() 103 spinBoxLayout.addWidget(integerLabel) 104 spinBoxLayout.addWidget(integerSpinBox) 105 spinBoxLayout.addWidget(zoomLabel) 106 spinBoxLayout.addWidget(zoomSpinBox) 107 spinBoxLayout.addWidget(priceLabel) 108 spinBoxLayout.addWidget(priceSpinBox) 109 spinBoxesGroup.setLayout(spinBoxLayout) 110 111//! [5] 112 113//! [6] 114def createDateTimeEdits(self): 115 editsGroup = QGroupBox(tr("Date and time spin boxes")) 116 117 dateLabel = QLabel() 118 dateEdit = QDateEdit(QDate.currentDate()) 119 dateEdit.setDateRange(QDate(2005, 1, 1), QDate(2010, 12, 31)) 120 dateLabel.setText(tr("Appointment date (between %0 and %1):") 121 .arg(dateEdit.minimumDate().toString(Qt.ISODate)) 122 .arg(dateEdit.maximumDate().toString(Qt.ISODate))) 123//! [6] 124 125//! [7] 126 timeLabel = QLabel() 127 timeEdit = QTimeEdit(QTime.currentTime()) 128 timeEdit.setTimeRange(QTime(9, 0, 0, 0), QTime(16, 30, 0, 0)) 129 timeLabel.setText(tr("Appointment time (between %0 and %1):") 130 .arg(timeEdit.minimumTime().toString(Qt.ISODate)) 131 .arg(timeEdit.maximumTime().toString(Qt.ISODate))) 132//! [7] 133 134//! [8] 135 meetingLabel = QLabel() 136 meetingEdit = QDateTimeEdit(QDateTime.currentDateTime()) 137//! [8] 138 139//! [9] 140 formatLabel = QLabel(tr("Format string for the meeting date " 141 "and time:")) 142 formatComboBox = QComboBox() 143 formatComboBox.addItem("yyyy-MM-dd hh:mm:ss (zzz 'ms')") 144 formatComboBox.addItem("hh:mm:ss MM/dd/yyyy") 145 formatComboBox.addItem("hh:mm:ss dd/MM/yyyy") 146 formatComboBox.addItem("hh:mm:ss") 147 formatComboBox.addItem("hh:mm ap") 148//! [9] //! [10] 149 150 formatComboBox.activated[str].connect(setFormatString) 151//! [10] 152 153 setFormatString(formatComboBox.currentText()) 154 155//! [11] 156 editsLayout = QVBoxLayout() 157 editsLayout.addWidget(dateLabel) 158 editsLayout.addWidget(dateEdit) 159 editsLayout.addWidget(timeLabel) 160 editsLayout.addWidget(timeEdit) 161 editsLayout.addWidget(meetingLabel) 162 editsLayout.addWidget(meetingEdit) 163 editsLayout.addWidget(formatLabel) 164 editsLayout.addWidget(formatComboBox) 165 editsGroup.setLayout(editsLayout) 166//! [11] 167 168//! [12] 169def setFormatString(self, formatString): 170 meetingEdit.setDisplayFormat(formatString) 171//! [12] //! [13] 172 if meetingEdit.displayedSections() & QDateTimeEdit.DateSections_Mask: 173 meetingEdit.setDateRange(QDate(2004, 11, 1), QDate(2005, 11, 30)) 174 meetingLabel.setText(tr("Meeting date (between %0 and %1):") 175 .arg(meetingEdit.minimumDate().toString(Qt.ISODate)) 176 .arg(meetingEdit.maximumDate().toString(Qt.ISODate))) 177 else: 178 meetingEdit.setTimeRange(QTime(0, 7, 20, 0), QTime(21, 0, 0, 0)) 179 meetingLabel.setText(tr("Meeting time (between %0 and %1):") 180 .arg(meetingEdit.minimumTime().toString(Qt.ISODate)) 181 .arg(meetingEdit.maximumTime().toString(Qt.ISODate))) 182//! [13] 183 184//! [14] 185def createDoubleSpinBoxes(): 186 doubleSpinBoxesGroup = QGroupBox(tr("Double precision spinboxes")) 187 188 precisionLabel = QLabel(tr("Number of decimal places " 189 "to show:")) 190 precisionSpinBox = QSpinBox() 191 precisionSpinBox.setRange(0, 100) 192 precisionSpinBox.setValue(2) 193//! [14] 194 195//! [15] 196 doubleLabel = QLabel(tr("Enter a value between " 197 "%1 and %2:").arg(-20).arg(20)) 198 doubleSpinBox = QDoubleSpinBox () 199 doubleSpinBox.setRange(-20.0, 20.0) 200 doubleSpinBox.setSingleStep(1.0) 201 doubleSpinBox.setValue(0.0) 202//! [15] 203 204//! [16] 205 scaleLabel = QLabel(tr("Enter a scale factor between " 206 "%1 and %2:").arg(0).arg(1000.0)) 207 scaleSpinBox = QDoubleSpinBox() 208 scaleSpinBox.setRange(0.0, 1000.0) 209 scaleSpinBox.setSingleStep(10.0) 210 scaleSpinBox.setSuffix("%") 211 scaleSpinBox.setSpecialValueText(tr("No scaling")) 212 scaleSpinBox.setValue(100.0) 213//! [16] 214 215//! [17] 216 priceLabel = QLabel(tr("Enter a price between " 217 "%1 and %2:").arg(0).arg(1000)) 218 priceSpinBox = QDoubleSpinBox() 219 priceSpinBox.setRange(0.0, 1000.0) 220 priceSpinBox.setSingleStep(1.0) 221 priceSpinBox.setPrefix("$") 222 priceSpinBox.setValue(99.99) 223 224 precisionSpinBox.valueChanged[int].connect(changePrecision) 225//! [17] 226 227//! [18] 228 spinBoxLayout = QVBoxLayout() 229 spinBoxLayout.addWidget(precisionLabel) 230 spinBoxLayout.addWidget(precisionSpinBox) 231 spinBoxLayout.addWidget(doubleLabel) 232 spinBoxLayout.addWidget(doubleSpinBox) 233 spinBoxLayout.addWidget(scaleLabel) 234 spinBoxLayout.addWidget(scaleSpinBox) 235 spinBoxLayout.addWidget(priceLabel) 236 spinBoxLayout.addWidget(priceSpinBox) 237 doubleSpinBoxesGroup.setLayout(spinBoxLayout) 238} 239//! [18] 240 241//! [19] 242def changePrecision(self, int) 243 doubleSpinBox.setDecimals(decimals) 244 scaleSpinBox.setDecimals(decimals) 245 priceSpinBox.setDecimals(decimals) 246 247//! [19] 248