• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python QtWidgets.QDoubleSpinBox类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中qgis.PyQt.QtWidgets.QDoubleSpinBox的典型用法代码示例。如果您正苦于以下问题:Python QDoubleSpinBox类的具体用法?Python QDoubleSpinBox怎么用?Python QDoubleSpinBox使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了QDoubleSpinBox类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: __init__

    def __init__(self, parameter, parent=None):
        """Constructor.

        :param parameter: A DefaultValueParameter object.
        :type parameter: DefaultValueParameter

        """
        super(DefaultValueParameterWidget, self).__init__(parameter, parent)

        self.radio_button_layout = QHBoxLayout()

        # Create radio button group
        self.input_button_group = QButtonGroup()

        for i in range(len(self._parameter.labels)):
            if '%s' in self._parameter.labels[i]:
                label = (
                    self._parameter.labels[i] %
                    self._parameter.options[i])
            else:
                label = self._parameter.labels[i]

            radio_button = QRadioButton(label)
            self.radio_button_layout.addWidget(radio_button)
            self.input_button_group.addButton(radio_button, i)
            if self._parameter.value == \
                    self._parameter.options[i]:
                radio_button.setChecked(True)

        # Create double spin box for custom value
        self.custom_value = QDoubleSpinBox()
        self.custom_value.setSingleStep(0.1)
        if self._parameter.options[-1]:
            self.custom_value.setValue(self._parameter.options[-1])
        self.radio_button_layout.addWidget(self.custom_value)

        self.toggle_custom_value()

        self.inner_input_layout.addLayout(self.radio_button_layout)

        # Connect
        # noinspection PyUnresolvedReferences
        self.input_button_group.buttonClicked.connect(
            self.toggle_custom_value)
开发者ID:inasafe,项目名称:inasafe,代码行数:44,代码来源:default_value_parameter_widget.py


示例2: testLinkedWidgets

    def testLinkedWidgets(self):
        """ test linking spin boxes to combobox"""
        w = qgis.gui.QgsLayoutUnitsComboBox()
        self.assertFalse(w.converter())
        c = QgsLayoutMeasurementConverter()
        w.setConverter(c)
        self.assertEqual(w.converter(), c)

        spin = QDoubleSpinBox()
        spin.setMaximum(1000000)
        spin.setValue(100)
        w.setUnit(QgsUnitTypes.LayoutCentimeters)
        w.linkToWidget(spin)
        w.setUnit(QgsUnitTypes.LayoutMeters)
        self.assertAlmostEqual(spin.value(), 1.0, 2)
        w.setUnit(QgsUnitTypes.LayoutMillimeters)
        self.assertAlmostEqual(spin.value(), 1000.0, 2)

        spin2 = QDoubleSpinBox()
        spin2.setValue(50)
        spin2.setMaximum(1000000)
        w.linkToWidget(spin2)
        w.setUnit(QgsUnitTypes.LayoutCentimeters)
        self.assertAlmostEqual(spin.value(), 100.0, 2)
        self.assertAlmostEqual(spin2.value(), 5.0, 2)

        # no crash!
        del spin
        w.setUnit(QgsUnitTypes.LayoutMeters)
        self.assertAlmostEqual(spin2.value(), 0.05, 2)
开发者ID:sbrunner,项目名称:QGIS,代码行数:30,代码来源:test_qgslayoutunitscombobox.py


示例3: testLinkedWidgets

    def testLinkedWidgets(self):
        """ test linking spin boxes to combobox"""
        w = qgis.gui.QgsRatioLockButton()

        spin_width = QDoubleSpinBox()
        spin_width.setMaximum(100000)
        spin_height = QDoubleSpinBox()
        spin_height.setMaximum(100000)

        w.setWidthSpinBox(spin_width)
        spin_width.setValue(1000)
        self.assertEqual(spin_width.value(), 1000)

        w.setLocked(True)
        spin_width.setValue(2000)
        self.assertEqual(spin_width.value(), 2000)
        w.setLocked(False)

        w.setHeightSpinBox(spin_height)
        spin_width.setValue(1000)
        self.assertEqual(spin_width.value(), 1000)
        self.assertEqual(spin_height.value(), 0)

        w.setLocked(True)
        spin_width.setValue(2000)
        self.assertEqual(spin_width.value(), 2000)
        self.assertEqual(spin_height.value(), 0)

        spin_height.setValue(1000)
        self.assertEqual(spin_width.value(), 2000)
        self.assertEqual(spin_height.value(), 1000)

        # ok, that was all setup tests... let's check the real thing now
        spin_width.setValue(1000)
        self.assertEqual(spin_width.value(), 1000)
        self.assertEqual(spin_height.value(), 500)
        spin_height.setValue(1000)
        self.assertEqual(spin_width.value(), 2000)
        self.assertEqual(spin_height.value(), 1000)

        w.setLocked(False)
        spin_width.setValue(1000)
        self.assertEqual(spin_width.value(), 1000)
        self.assertEqual(spin_height.value(), 1000)
        spin_height.setValue(2000)
        self.assertEqual(spin_width.value(), 1000)
        self.assertEqual(spin_height.value(), 2000)

        w.setLocked(True)
        spin_height.setValue(1000)
        self.assertEqual(spin_width.value(), 500)
        self.assertEqual(spin_height.value(), 1000)

        # setting to 0 should "break" lock
        spin_height.setValue(0)
        self.assertEqual(spin_width.value(), 500)
        self.assertEqual(spin_height.value(), 0)
        spin_width.setValue(1000)
        self.assertEqual(spin_width.value(), 1000)
        self.assertEqual(spin_height.value(), 0)
        spin_height.setValue(100)
        self.assertEqual(spin_width.value(), 1000)
        self.assertEqual(spin_height.value(), 100)

        spin_width.setValue(0)
        self.assertEqual(spin_width.value(), 0)
        self.assertEqual(spin_height.value(), 100)
        spin_height.setValue(1000)
        self.assertEqual(spin_width.value(), 0)
        self.assertEqual(spin_height.value(), 1000)
        spin_width.setValue(200)
        self.assertEqual(spin_width.value(), 200)
        self.assertEqual(spin_height.value(), 1000)
开发者ID:elpaso,项目名称:QGIS,代码行数:73,代码来源:test_qgsratiolockbutton.py


示例4: testResetRatio

    def testResetRatio(self):
        w = qgis.gui.QgsRatioLockButton()

        spin_width = QDoubleSpinBox()
        spin_width.setMaximum(100000)
        spin_height = QDoubleSpinBox()
        spin_height.setMaximum(100000)

        spin_width.setValue(1000)
        w.setWidthSpinBox(spin_width)
        spin_height.setValue(500)
        w.setHeightSpinBox(spin_height)

        w.setLocked(True)
        spin_width.setValue(2000)
        self.assertEqual(spin_height.value(), 1000)

        spin_width.blockSignals(True)
        spin_width.setValue(1000)
        spin_width.blockSignals(False)

        spin_height.setValue(2000)
        self.assertEqual(spin_width.value(), 4000)  # signals were blocked, so ratio wasn't updated

        spin_width.blockSignals(True)
        spin_width.setValue(2000)
        spin_width.blockSignals(False)
        w.resetRatio() # since signals were blocked, we need to manually reset ratio
        spin_height.setValue(1000)
        self.assertEqual(spin_width.value(), 1000)
开发者ID:elpaso,项目名称:QGIS,代码行数:30,代码来源:test_qgsratiolockbutton.py


示例5: DefaultValueParameterWidget

class DefaultValueParameterWidget(GenericParameterWidget):

    """Widget class for Default Value Parameter."""

    def __init__(self, parameter, parent=None):
        """Constructor.

        :param parameter: A DefaultValueParameter object.
        :type parameter: DefaultValueParameter

        """
        super(DefaultValueParameterWidget, self).__init__(parameter, parent)

        self.radio_button_layout = QHBoxLayout()

        # Create radio button group
        self.input_button_group = QButtonGroup()

        for i in range(len(self._parameter.labels)):
            if '%s' in self._parameter.labels[i]:
                label = (
                    self._parameter.labels[i] %
                    self._parameter.options[i])
            else:
                label = self._parameter.labels[i]

            radio_button = QRadioButton(label)
            self.radio_button_layout.addWidget(radio_button)
            self.input_button_group.addButton(radio_button, i)
            if self._parameter.value == \
                    self._parameter.options[i]:
                radio_button.setChecked(True)

        # Create double spin box for custom value
        self.custom_value = QDoubleSpinBox()
        self.custom_value.setSingleStep(0.1)
        if self._parameter.options[-1]:
            self.custom_value.setValue(self._parameter.options[-1])
        self.radio_button_layout.addWidget(self.custom_value)

        self.toggle_custom_value()

        self.inner_input_layout.addLayout(self.radio_button_layout)

        # Connect
        # noinspection PyUnresolvedReferences
        self.input_button_group.buttonClicked.connect(
            self.toggle_custom_value)

    def raise_invalid_type_exception(self):
        """Raise invalid type."""
        message = 'Expecting element type of %s' % (
            self._parameter.element_type.__name__)
        err = ValueError(message)
        return err

    def get_parameter(self):
        """Obtain list parameter object from the current widget state.

        :returns: A DefaultValueParameter from the current state of widget
        :rtype: DefaultValueParameter
        """
        radio_button_checked_id = self.input_button_group.checkedId()
        # No radio button checked, then default value = None
        if radio_button_checked_id == -1:
            self._parameter.value = None
        # The last radio button (custom) is checked, get the value from the
        # line edit
        elif radio_button_checked_id == len(self._parameter.options) - 1:
            self._parameter.options[radio_button_checked_id] = \
                self.custom_value.value()
            self._parameter.value = self.custom_value.value()
        else:
            self._parameter.value = self._parameter.options[
                radio_button_checked_id]

        return self._parameter

    def set_value(self, value):
        """Set value by item's string.

        :param value: The value.
        :type value: str, int

        :returns: True if success, else False.
        :rtype: bool
        """
        # Find index of choice
        try:
            value_index = self._parameter.options.index(value)
            self.input_button_group.button(value_index).setChecked(True)
        except ValueError:
            last_index = len(self._parameter.options) - 1
            self.input_button_group.button(last_index).setChecked(
                True)
            self.custom_value.setValue(value)

        self.toggle_custom_value()

    def toggle_custom_value(self):
#.........这里部分代码省略.........
开发者ID:inasafe,项目名称:inasafe,代码行数:101,代码来源:default_value_parameter_widget.py


示例6: set_widgets

    def set_widgets(self):
        """Set widgets on the Threshold tab."""
        clear_layout(self.gridLayoutThreshold)

        # Set text in the label
        layer_purpose = self.parent.step_kw_purpose.selected_purpose()
        layer_subcategory = self.parent.step_kw_subcategory.\
            selected_subcategory()
        classification = self.parent.step_kw_classification. \
            selected_classification()

        if is_raster_layer(self.parent.layer):
            statistics = self.parent.layer.dataProvider().bandStatistics(
                1, QgsRasterBandStats.All, self.parent.layer.extent(), 0)
            text = continuous_raster_question % (
                layer_purpose['name'],
                layer_subcategory['name'],
                classification['name'],
                statistics.minimumValue,
                statistics.maximumValue)
        else:
            field_name = self.parent.step_kw_field.selected_fields()
            field_index = self.parent.layer.fields().lookupField(field_name)
            min_value_layer = self.parent.layer.minimumValue(field_index)
            max_value_layer = self.parent.layer.maximumValue(field_index)
            text = continuous_vector_question % (
                layer_purpose['name'],
                layer_subcategory['name'],
                field_name,
                classification['name'],
                min_value_layer,
                max_value_layer)
        self.lblThreshold.setText(text)

        thresholds = self.parent.get_existing_keyword('thresholds')
        selected_unit = self.parent.step_kw_unit.selected_unit()['key']

        self.classes = OrderedDict()
        classes = classification.get('classes')
        # Sort by value, put the lowest first
        classes = sorted(classes, key=lambda k: k['value'])

        for i, the_class in enumerate(classes):
            class_layout = QHBoxLayout()

            # Class label
            class_label = QLabel(the_class['name'])

            # Min label
            min_label = QLabel(tr('Min >'))

            # Min value as double spin
            min_value_input = QDoubleSpinBox()
            # TODO(IS) We can set the min and max depends on the unit, later
            min_value_input.setMinimum(0)
            min_value_input.setMaximum(999999)
            if thresholds.get(the_class['key']):
                min_value_input.setValue(thresholds[the_class['key']][0])
            else:
                default_min = the_class['numeric_default_min']
                if isinstance(default_min, dict):
                    default_min = the_class[
                        'numeric_default_min'][selected_unit]
                min_value_input.setValue(default_min)
            min_value_input.setSingleStep(0.1)

            # Max label
            max_label = QLabel(tr('Max <='))

            # Max value as double spin
            max_value_input = QDoubleSpinBox()
            # TODO(IS) We can set the min and max depends on the unit, later
            max_value_input.setMinimum(0)
            max_value_input.setMaximum(999999)
            if thresholds.get(the_class['key']):
                max_value_input.setValue(thresholds[the_class['key']][1])
            else:
                default_max = the_class['numeric_default_max']
                if isinstance(default_max, dict):
                    default_max = the_class[
                        'numeric_default_max'][selected_unit]
                max_value_input.setValue(default_max)
            max_value_input.setSingleStep(0.1)

            # Add to class_layout
            class_layout.addWidget(min_label)
            class_layout.addWidget(min_value_input)
            # class_layout.addStretch(1)
            class_layout.addWidget(max_label)
            class_layout.addWidget(max_value_input)

            # Add to grid_layout
            self.gridLayoutThreshold.addWidget(class_label, i, 0)
            self.gridLayoutThreshold.addLayout(class_layout, i, 1)

            self.classes[the_class['key']] = [min_value_input, max_value_input]

        self.gridLayoutThreshold.setSpacing(0)

        def min_max_changed(index, the_string):
#.........这里部分代码省略.........
开发者ID:inasafe,项目名称:inasafe,代码行数:101,代码来源:step_kw43_threshold.py


示例7: setup_thresholds_panel

    def setup_thresholds_panel(self, classification):
        """Setup threshold panel in the right panel.

        :param classification: Classification definition.
        :type classification: dict
        """
        # Set text in the label
        layer_purpose = self.parent.step_kw_purpose.selected_purpose()
        layer_subcategory = self.parent.step_kw_subcategory.\
            selected_subcategory()

        if is_raster_layer(self.parent.layer):
            active_band = self.parent.step_kw_band_selector.selected_band()
            layer_extent = self.parent.layer.extent()
            statistics = self.parent.layer.dataProvider().bandStatistics(
                active_band, QgsRasterBandStats.All, layer_extent, 0)
            description_text = continuous_raster_question % (
                layer_purpose['name'],
                layer_subcategory['name'],
                classification['name'],
                statistics.minimumValue,
                statistics.maximumValue)
        else:
            field_name = self.parent.step_kw_field.selected_fields()
            field_index = self.parent.layer.fields().lookupField(field_name)
            min_value_layer = self.parent.layer.minimumValue(field_index)
            max_value_layer = self.parent.layer.maximumValue(field_index)
            description_text = continuous_vector_question % (
                layer_purpose['name'],
                layer_subcategory['name'],
                field_name,
                classification['name'],
                min_value_layer,
                max_value_layer)

        # Set description
        description_label = QLabel(description_text)
        description_label.setWordWrap(True)
        self.right_layout.addWidget(description_label)

        if self.thresholds:
            thresholds = self.thresholds
        else:
            thresholds = self.parent.get_existing_keyword('thresholds')
        selected_unit = self.parent.step_kw_unit.selected_unit()['key']

        self.threshold_classes = OrderedDict()
        classes = classification.get('classes')
        # Sort by value, put the lowest first
        classes = sorted(classes, key=lambda the_key: the_key['value'])

        grid_layout_thresholds = QGridLayout()

        for i, the_class in enumerate(classes):
            class_layout = QHBoxLayout()

            # Class label
            class_label = QLabel(the_class['name'])

            # Min label
            min_label = QLabel(tr('Min >'))

            # Min value as double spin
            min_value_input = QDoubleSpinBox()
            # TODO(IS) We can set the min and max depends on the unit, later
            min_value_input.setMinimum(0)
            min_value_input.setMaximum(999999)

            if thresholds.get(self.active_exposure['key']):
                exposure_thresholds = thresholds.get(
                    self.active_exposure['key'])
                if exposure_thresholds.get(classification['key']):
                    exposure_thresholds_classifications = exposure_thresholds\
                        .get(classification['key'])
                    min_value_input.setValue(
                        exposure_thresholds_classifications['classes'][
                            the_class['key']][0])
                else:
                    default_min = the_class['numeric_default_min']
                    if isinstance(default_min, dict):
                        default_min = the_class[
                            'numeric_default_min'][selected_unit]
                    min_value_input.setValue(default_min)
            else:
                default_min = the_class['numeric_default_min']
                if isinstance(default_min, dict):
                    default_min = the_class[
                        'numeric_default_min'][selected_unit]
                min_value_input.setValue(default_min)
            min_value_input.setSingleStep(0.1)

            # Max label
            max_label = QLabel(tr('Max <='))

            # Max value as double spin
            max_value_input = QDoubleSpinBox()
            # TODO(IS) We can set the min and max depends on the unit, later
            max_value_input.setMinimum(0)
            max_value_input.setMaximum(999999)
            if thresholds.get(self.active_exposure['key']):
#.........这里部分代码省略.........
开发者ID:inasafe,项目名称:inasafe,代码行数:101,代码来源:step_kw33_multi_classifications.py


示例8: extra_keywords_to_widgets

def extra_keywords_to_widgets(extra_keyword_definition):
    """Create widgets for extra keyword.

    :param extra_keyword_definition: An extra keyword definition.
    :type extra_keyword_definition: dict

    :return: QCheckBox and The input widget
    :rtype: (QCheckBox, QWidget)
    """
    # Check box
    check_box = QCheckBox(extra_keyword_definition['name'])
    check_box.setToolTip(extra_keyword_definition['description'])
    check_box.setChecked(True)

    # Input widget
    if extra_keyword_definition['type'] == float:
        input_widget = QDoubleSpinBox()
        input_widget.setMinimum(extra_keyword_definition['minimum'])
        input_widget.setMaximum(extra_keyword_definition['maximum'])
        input_widget.setSuffix(extra_keyword_definition['unit_string'])
    elif extra_keyword_definition['type'] == int:
        input_widget = QSpinBox()
        input_widget.setMinimum(extra_keyword_definition['minimum'])
        input_widget.setMaximum(extra_keyword_definition['maximum'])
        input_widget.setSuffix(extra_keyword_definition['unit_string'])
    elif extra_keyword_definition['type'] == str:
        if extra_keyword_definition.get('options'):
            input_widget = QComboBox()
            options = extra_keyword_definition['options']
            for option in options:
                input_widget.addItem(
                    option['name'],
                    option['key'],
                )
            default_option_index = input_widget.findData(
                extra_keyword_definition['default_option'])
            input_widget.setCurrentIndex(default_option_index)
        else:
            input_widget = QLineEdit()
    elif extra_keyword_definition['type'] == datetime:
        input_widget = QDateTimeEdit()
        input_widget.setCalendarPopup(True)
        input_widget.setDisplayFormat('hh:mm:ss, d MMM yyyy')
        input_widget.setDateTime(datetime.now())
    else:
        raise Exception
    input_widget.setToolTip(extra_keyword_definition['description'])

    # Signal
    # noinspection PyUnresolvedReferences
    check_box.stateChanged.connect(input_widget.setEnabled)

    return check_box, input_widget
开发者ID:inasafe,项目名称:inasafe,代码行数:53,代码来源:step_kw57_extra_keywords.py


示例9: getSpinBoxOffset

 def getSpinBoxOffset(wgt, value):
   sp = QDoubleSpinBox( wgt)
   sp.setRange(0.0, 50.0)
   sp.setSingleStep(12.5)
   sp.setDecimals(2)
   sp.setSuffix(' %')
   sp.setValue(value)
   return sp
开发者ID:lmotta,项目名称:gimpselectionfeature_plugin,代码行数:8,代码来源:gimpselectionfeature.py



注:本文中的qgis.PyQt.QtWidgets.QDoubleSpinBox类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python QtWidgets.QFileDialog类代码示例发布时间:2022-05-26
下一篇:
Python QtWidgets.QDialogButtonBox类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap