本文整理匯總了Python中qtpy.QtWidgets.QStackedWidget.setCurrentIndex方法的典型用法代碼示例。如果您正苦於以下問題:Python QStackedWidget.setCurrentIndex方法的具體用法?Python QStackedWidget.setCurrentIndex怎麽用?Python QStackedWidget.setCurrentIndex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類qtpy.QtWidgets.QStackedWidget
的用法示例。
在下文中一共展示了QStackedWidget.setCurrentIndex方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: CalibrationWidget
# 需要導入模塊: from qtpy.QtWidgets import QStackedWidget [as 別名]
# 或者: from qtpy.QtWidgets.QStackedWidget import setCurrentIndex [as 別名]
class CalibrationWidget(ParameterWidget):
def __init__(self, parent=None):
ParameterWidget.__init__(self, _Calibration, parent)
def _init_ui(self):
# Widgets
self._combobox = QComboBox()
self._stack = QStackedWidget()
# Layouts
layout = ParameterWidget._init_ui(self)
layout.addRow(self._combobox)
layout.addRow(self._stack)
# Register classes
self._widget_indexes = {}
for entry_point in iter_entry_points('pyhmsa_gui.spec.condition.calibration'):
widget_class = entry_point.load(require=False)
widget = widget_class()
self._combobox.addItem(widget.accessibleName().title())
self._widget_indexes[widget.CLASS] = self._stack.addWidget(widget)
widget.edited.connect(self.edited)
# Signals
self._combobox.currentIndexChanged.connect(self._on_combo_box)
self._combobox.currentIndexChanged.connect(self.edited)
return layout
def _on_combo_box(self):
# Old values
oldwidget = self._stack.currentWidget()
try:
quantity = oldwidget._txt_quantity.text()
except:
quantity = None
try:
unit = oldwidget._txt_unit.text()
except:
unit = None
# Change widget
current_index = self._combobox.currentIndex()
self._stack.setCurrentIndex(current_index)
# Update values
widget = self._stack.currentWidget()
widget._txt_quantity.setText(quantity)
widget._txt_unit.setText(unit)
def parameter(self):
return self._stack.currentWidget().calibration()
def setParameter(self, calibration):
index = self._widget_indexes[type(calibration)]
self._combobox.setCurrentIndex(index)
self._stack.setCurrentIndex(index)
self._stack.currentWidget().setParameter(calibration)
def calibration(self):
return self.parameter()
def setCalibration(self, calibration):
self.setParameter(calibration)
def setReadOnly(self, state):
ParameterWidget.setReadOnly(self, state)
self._combobox.setEnabled(not state)
self._stack.currentWidget().setReadOnly(state)
def isReadOnly(self):
return ParameterWidget.isReadOnly(self) and \
not self._combobox.isEnabled() and \
self._stack.currentWidget().isReadOnly()
def hasAcceptableInput(self):
return ParameterWidget.hasAcceptableInput(self) and \
self._stack.currentWidget().hasAcceptableInput()
示例2: ArrayEditor
# 需要導入模塊: from qtpy.QtWidgets import QStackedWidget [as 別名]
# 或者: from qtpy.QtWidgets.QStackedWidget import setCurrentIndex [as 別名]
#.........這裏部分代碼省略.........
text = name
if len(field) >= 3:
title = field[2]
if not is_text_string(title):
title = repr(title)
text += ' - '+title
names.append(text)
else:
names = [_('Masked data'), _('Data'), _('Mask')]
if data.ndim == 3:
# QSpinBox
self.index_spin = QSpinBox(self, keyboardTracking=False)
self.index_spin.valueChanged.connect(self.change_active_widget)
# QComboBox
names = [str(i) for i in range(3)]
ra_combo = QComboBox(self)
ra_combo.addItems(names)
ra_combo.currentIndexChanged.connect(self.current_dim_changed)
# Adding the widgets to layout
label = QLabel(_("Axis:"))
btn_layout.addWidget(label)
btn_layout.addWidget(ra_combo)
self.shape_label = QLabel()
btn_layout.addWidget(self.shape_label)
label = QLabel(_("Index:"))
btn_layout.addWidget(label)
btn_layout.addWidget(self.index_spin)
self.slicing_label = QLabel()
btn_layout.addWidget(self.slicing_label)
# set the widget to display when launched
self.current_dim_changed(self.last_dim)
else:
ra_combo = QComboBox(self)
ra_combo.currentIndexChanged.connect(self.stack.setCurrentIndex)
ra_combo.addItems(names)
btn_layout.addWidget(ra_combo)
if is_masked_array:
label = QLabel(_("<u>Warning</u>: changes are applied separately"))
label.setToolTip(_("For performance reasons, changes applied "\
"to masked array won't be reflected in "\
"array's data (and vice-versa)."))
btn_layout.addWidget(label)
btn_layout.addStretch()
bbox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
bbox.accepted.connect(self.accept)
bbox.rejected.connect(self.reject)
btn_layout.addWidget(bbox)
self.layout.addLayout(btn_layout, 2, 0)
self.setMinimumSize(400, 300)
# Make the dialog act as a window
self.setWindowFlags(Qt.Window)
return True
def current_widget_changed(self, index):
self.arraywidget = self.stack.widget(index)
def change_active_widget(self, index):
"""
This is implemented for handling negative values in index for
3d arrays, to give the same behavior as slicing
"""
string_index = [':']*3
string_index[self.last_dim] = '<font color=red>%i</font>'
示例3: MixerPanel
# 需要導入模塊: from qtpy.QtWidgets import QStackedWidget [as 別名]
# 或者: from qtpy.QtWidgets.QStackedWidget import setCurrentIndex [as 別名]
#.........這裏部分代碼省略.........
self.sig_gamma_widget = QWidget()
self.sig_gamma_widget.layout = QGridLayout(self.sig_gamma_widget)
self.sig_gamma_widget.layout.addWidget(self.a_gamma, 0, 0)
self.sig_gamma_widget.layout.addWidget(self.b_gamma, 0, 1)
#---------------------------------------------------------------
# Buttons
#---------------------------------------------------------------
self.commit_button = QPushButton('Commit')
self.commit_button.clicked.connect(self.commit_changes)
self.revert_button = QPushButton('Revert')
self.revert_button.clicked.connect(self.revert_changes)
#---------------------------------------------------------------
# Mixer Layout
#---------------------------------------------------------------
self.sliders = QStackedWidget()
self.sliders.addWidget(self.rgb_widget)
self.sliders.addWidget(self.hsv_widget)
self.sliders.addWidget(self.bright_widget)
self.sliders.addWidget(self.gamma_widget)
self.sliders.addWidget(self.sig_gamma_widget)
self.layout = QGridLayout(self)
self.layout.addWidget(self.combo_box, 0, 0)
self.layout.addWidget(self.sliders, 1, 0)
self.layout.addWidget(self.commit_button, 2, 0)
self.layout.addWidget(self.revert_button, 3, 0)
#---------------------------------------------------------------
# State Initialization
#---------------------------------------------------------------
self.combo_box.setCurrentIndex(0)
self.rgb_mul.setChecked(True)
self.hsv_mul.setChecked(True)
def set_callback(self, callback):
self.callback = callback
def combo_box_changed(self, index):
self.sliders.setCurrentIndex(index)
self.reset()
def rgb_radio_changed(self):
self.reset()
def hsv_radio_changed(self):
self.reset()
def reset(self):
self.reset_sliders()
self.mixer.set_to_stateimg()
if self.callback:
self.callback()
def reset_sliders(self):
# handle changing the conversion factors necessary
if self.rgb_add.isChecked():
self.rs.set_conv_fac(0.51, -255)
self.rs.set_value(0)
self.gs.set_conv_fac(0.51, -255)
self.gs.set_value(0)
self.bs.set_conv_fac(0.51, -255)
self.bs.set_value(0)
else: