本文整理匯總了Python中PySide.QtGui.QSlider.isEnabled方法的典型用法代碼示例。如果您正苦於以下問題:Python QSlider.isEnabled方法的具體用法?Python QSlider.isEnabled怎麽用?Python QSlider.isEnabled使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PySide.QtGui.QSlider
的用法示例。
在下文中一共展示了QSlider.isEnabled方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: SelectorView
# 需要導入模塊: from PySide.QtGui import QSlider [as 別名]
# 或者: from PySide.QtGui.QSlider import isEnabled [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))