本文整理汇总了Python中PySide.QtGui.QSlider.triggerAction方法的典型用法代码示例。如果您正苦于以下问题:Python QSlider.triggerAction方法的具体用法?Python QSlider.triggerAction怎么用?Python QSlider.triggerAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QSlider
的用法示例。
在下文中一共展示了QSlider.triggerAction方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SelectorView
# 需要导入模块: from PySide.QtGui import QSlider [as 别名]
# 或者: from PySide.QtGui.QSlider import triggerAction [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))