本文整理汇总了Python中PySide.QtGui.QSlider.setSingleStep方法的典型用法代码示例。如果您正苦于以下问题:Python QSlider.setSingleStep方法的具体用法?Python QSlider.setSingleStep怎么用?Python QSlider.setSingleStep使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QSlider
的用法示例。
在下文中一共展示了QSlider.setSingleStep方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: NumericBox
# 需要导入模块: from PySide.QtGui import QSlider [as 别名]
# 或者: from PySide.QtGui.QSlider import setSingleStep [as 别名]
class NumericBox(QFrame):
"""
A box with a spinner and a slider to allow easier value manipulation by user
"""
valueChanged = Signal(float)
spinner = QDoubleSpinBox
step = 0.1
def __init__(self, parent=None):
super(NumericBox, self).__init__(parent)
self.slider = QSlider(Qt.Horizontal)
self.spinner = self.spinner()
self.spinner.setSingleStep(self.step)
self.slider.setTickInterval(self.step * 100)
self.slider.setSingleStep(self.step * 100)
self.slider.sliderMoved.connect(lambda x: self.spinner.setValue(x / 100))
self.spinner.valueChanged.connect(self.applyValue)
self.setLayout(line(self.slider, self.spinner))
self.layout().setStretch(1, 0)
def applyValue(self, value):
self.valueChanged.emit(value)
self.slider.setValue(value * 100)
def setValue(self, value):
self.spinner.setValue(value)
self.slider.setValue(value * 100)
def setRange(self, mini, maxi):
self.spinner.setRange(mini, maxi)
self.slider.setRange(mini * 100, maxi * 100)
def value(self):
return self.spinner.value()
示例2: ParameterSlider
# 需要导入模块: from PySide.QtGui import QSlider [as 别名]
# 或者: from PySide.QtGui.QSlider import setSingleStep [as 别名]
class ParameterSlider(QWidget):
'''ParameterSlider is a QSlider combined with a QLabel to display the
current value of the slider
Arguments
---------
parent : QWidget
parent widget
name : str
name of the parameter the slider represents. Will be used as 'name = '
prefix for the label
'''
valueChanged = Signal()
def __init__(self, parent=None, name=None):
QWidget.__init__(self, parent)
self.name = name
self.set_format('.3f')
# create widgets
self.label = QLabel()
self.slider = QSlider(QtCore.Qt.Orientation.Horizontal)
self.slider.valueChanged.connect(self._update_label)
# set default values
self.set_range(0, 100)
self.set_value(50)
# create layout for the entire widget
box = QVBoxLayout()
box.addWidget(self.label)
box.addWidget(self.slider)
self.setLayout(box)
def _convert(self, value, inverse=False):
if inverse == True:
# slider value -> true value
return self.offset + self.delta * float(value) / self.ticks
else:
# true value -> slider value
return (value - self.offset) * self.ticks / self.delta
@Slot()
def _update_label(self, value):
# convert value to external range
value = self._convert(value, inverse=True)
if self.name is None:
# no name given -> show just 'value'
text = self.format_str.format(value)
else:
# name given -> show 'name = value'
text = self.format_str.format(self.name, value)
self.label.setText(text)
self.valueChanged.emit()
def set_format(self, format_str):
if self.name is None:
self.format_str = '{:' + format_str + '}'
else:
self.format_str = '{} = {:' + format_str + '}'
def set_range(self, minimum, maximum, step=1):
# calculate settings
self.offset = float(minimum)
self.delta = float(maximum - minimum)
self.ticks = int(self.delta / step)
# forward settings to widget
self.slider.setMinimum(0.0)
self.slider.setMaximum(self.ticks)
self.slider.setSingleStep(1.0)
def set_value(self, value):
# convert value to internal range
value = self._convert(float(value))
# set value and emit signal
self.slider.setValue(value)
self.slider.valueChanged.emit(value)
def value(self):
return self._convert(self.slider.value(), inverse=True)
示例3: EegCarDashboardWindow
# 需要导入模块: from PySide.QtGui import QSlider [as 别名]
# 或者: from PySide.QtGui.QSlider import setSingleStep [as 别名]
#.........这里部分代码省略.........
self.layout = QVBoxLayout(self)
# Drive Setting
self.rc_mode = QCheckBox('Remote Control', self)
self.rc_mode.stateChanged.connect(self.remote_control)
self.rc_stright_mode = QCheckBox('RC Stright', self)
self.rc_stright_mode.stateChanged.connect(self.stright_control)
self.keep_mode_checkbox = QCheckBox('Keep Mode', self)
self.keep_mode_checkbox.stateChanged.connect(self.keep_mode_control)
self.power_handle_mode_checkbox = QCheckBox('Power Handle', self)
self.power_handle_mode_checkbox.stateChanged.connect(self.power_handle_mode_control)
self.ignore_eeg_input = QCheckBox('Ignore Eeg Input', self)
self.ignore_eeg_input.stateChanged.connect(self.ignore_eeg_input_control)
drive_layout = QHBoxLayout(self)
drive_layout.addWidget(self.rc_mode)
drive_layout.addWidget(self.rc_stright_mode)
drive_layout.addWidget(self.keep_mode_checkbox)
drive_layout.addWidget(self.power_handle_mode_checkbox)
drive_layout.addWidget(self.ignore_eeg_input)
drive_groupbox = QtGui.QGroupBox("Drive Status & Setting")
drive_groupbox.setLayout(drive_layout)
# Throttle Setting
self.throttle_slider = QSlider(Qt.Horizontal)
self.throttle_slider.setFocusPolicy(Qt.StrongFocus)
self.throttle_slider.setTickPosition(QSlider.TicksBothSides)
self.throttle_slider.setTickInterval(10)
self.throttle_slider.setSingleStep(10)
self.throttle_slider.setValue(DEFAULT_MAX_THROTTLE)
self.throttle_slider.valueChanged.connect(self.throttle_slider.setValue)
self.connect(self.throttle_slider, SIGNAL("valueChanged(int)"), self.setSliderMaxThrottle)
self.throttle_label = QLabel('Max Throttle (%): ', self)
self.maxThrottle = QLineEdit(str(DEFAULT_MAX_THROTTLE))
# self.maxThrottle.textChanged[str].connect(self.setMaxThrottle)
self.maxThrottle.editingFinished.connect(self.setMaxThrottle)
self.maxThrottle.setMaxLength(2)
self.maxThrottle.setMaximumWidth(40)
self.backwardMaxThrottle = QLineEdit(str(DEFAULT_MAX_BACK_THROTTLE))
# self.maxThrottle.textChanged[str].connect(self.setMaxThrottle)
self.backwardMaxThrottle.editingFinished.connect(self.setBackwardMaxThrottle)
self.backwardMaxThrottle.setMaxLength(2)
self.backwardMaxThrottle.setMaximumWidth(40)
throttle_layout = QHBoxLayout(self)
throttle_layout.addWidget(self.throttle_label)
throttle_layout.addWidget(self.throttle_slider)
throttle_layout.addWidget(QLabel("Forward Max:"))
throttle_layout.addWidget(self.maxThrottle)
throttle_layout.addWidget(QLabel("Backward Max:"))
throttle_layout.addWidget(self.backwardMaxThrottle)
throttle_groupbox = QtGui.QGroupBox("Max Throttle Setting (30-99)")
throttle_groupbox.setLayout(throttle_layout)
# Steering
示例4: SelectorView
# 需要导入模块: from PySide.QtGui import QSlider [as 别名]
# 或者: from PySide.QtGui.QSlider import setSingleStep [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))