当前位置: 首页>>代码示例>>Python>>正文


Python QSlider.setEnabled方法代码示例

本文整理汇总了Python中PySide.QtGui.QSlider.setEnabled方法的典型用法代码示例。如果您正苦于以下问题:Python QSlider.setEnabled方法的具体用法?Python QSlider.setEnabled怎么用?Python QSlider.setEnabled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PySide.QtGui.QSlider的用法示例。


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

示例1: SelectorView

# 需要导入模块: from PySide.QtGui import QSlider [as 别名]
# 或者: from PySide.QtGui.QSlider import setEnabled [as 别名]
class SelectorView(QAbstractItemView):
    """View that sets selection by objects' relative size
    """
    def __init__(self, parent=None):
        # This view is not visible
        super(SelectorView, self).__init__(None)

        self._updating_selection = False

        layout = QHBoxLayout()
        layout.addWidget(QLabel("Select by size"))

        self.slider = QSlider(Qt.Horizontal)
        self.slider.setTickPosition(QSlider.TicksBothSides)
        self.slider.setMinimum(-1)
        self.slider.setMaximum(1)
        self.slider.setTickInterval(1)
        self.slider.setSingleStep(1)
        self.slider.setEnabled(False)

        self.slider.valueChanged.connect(self._slider_changed)

        # Slider has stretch greater than zero to force left-alignment
        layout.addWidget(self.slider, stretch=1)

        self.widget = QWidget(parent)
        self.widget.setLayout(layout)

    def _update_slider(self, n):
        """Sets the slider range and enabled state
        """
        self.slider.setEnabled(n > 0)
        if n:
            # Scale runs from -n to + n in steps of 1
            self.slider.setMinimum(-n)
            self.slider.setMaximum(n)
            self.slider.setTickInterval(n)
            self.slider.setSingleStep(1)
            self.slider.setValue(0)

    def _slider_changed(self, value):
        """QSlider.valueChanged slot
        """
        debug_print('SelectorView._slider_changed', value)
        if False and 0 == value:
            # Do not alter selection if value is 0
            pass
        else:
            # Order items by increasing / decreasing area and select the first n
            model = self.model()
            rows = xrange(model.rowCount())

            def box_area(row):
                rect = model.index(row, 0).data(RectRole)
                return rect.width() * rect.height()

            rows = sorted(rows, key=box_area, reverse=value < 0)
            self._updating_selection = True
            try:
                update_selection_model(model, self.selectionModel(), rows[:abs(value)])
            finally:
                self._updating_selection = False

    def single_step(self, larger):
        """Steps the slider up / down
        """
        if self.slider.isEnabled():
            action = QSlider.SliderSingleStepAdd if larger else QSlider.SliderSingleStepSub
            self.slider.triggerAction(action)

    def selectionChanged(self, selected, deselected):
        """QAbstractItemView virtual
        """
        if not self._updating_selection:
            self.slider.setValue(0)

    def reset(self):
        """QAbstractItemView virtual
        """
        debug_print('SelectorView.reset')
        super(SelectorView, self).reset()
        self._update_slider(self.model().rowCount())

    def dataChanged(self, topLeft, bottomRight):
        """QAbstractItemView virtual
        """
        debug_print('SelectorView.dataChanged')
        self._update_slider(self.model().rowCount())

    def rowsAboutToBeRemoved(self, parent, start, end):
        """QAbstractItemView slot
        """
        debug_print('SelectorView.rowsAboutToBeRemoved')
        self._update_slider(self.model().rowCount() - (end - start))
开发者ID:edwbaker,项目名称:inselect,代码行数:96,代码来源:selector.py


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