本文整理汇总了Python中PyQt5.QtWidgets.QStackedWidget.currentIndex方法的典型用法代码示例。如果您正苦于以下问题:Python QStackedWidget.currentIndex方法的具体用法?Python QStackedWidget.currentIndex怎么用?Python QStackedWidget.currentIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QStackedWidget
的用法示例。
在下文中一共展示了QStackedWidget.currentIndex方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: QChatTab
# 需要导入模块: from PyQt5.QtWidgets import QStackedWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedWidget import currentIndex [as 别名]
class QChatTab(QWidget):
def __init__(self, chat_window, nick=None, just_accepted=False):
QWidget.__init__(self)
self.chat_window = chat_window
self.nick = nick
self.just_accepted = just_accepted
self.unread_count = 0
self.widget_stack = QStackedWidget(self)
self.widget_stack.addWidget(QNickInputWidget('new_chat.png', 150, self.connectClicked, parent=self))
self.widget_stack.addWidget(QConnectingWidget(parent=self))
self.widget_stack.addWidget(QChatWidget(self.chat_window, nick=nick, parent=self))
if self.nick is not None:
self.widget_stack.setCurrentIndex(2)
else:
self.widget_stack.setCurrentIndex(0)
layout = QHBoxLayout()
layout.addWidget(self.widget_stack)
self.setLayout(layout)
def connectClicked(self, nick):
if self.chat_window.isNickInTabs(nick):
QMessageBox.warning(self, TITLE_ALREADY_CONNECTED, ALREADY_CONNECTED % (nick))
return
self.nick = nick
self.widget_stack.widget(1).setConnectingToNick(self.nick)
self.widget_stack.setCurrentIndex(1)
self.chat_window.client.openSession(self.nick)
self.widget_stack.widget(2).setRemoteNick(self.nick)
def appendMessage(self, message, source):
self.widget_stack.widget(2).appendMessage(message, source)
def showNowChattingMessage(self):
self.widget_stack.setCurrentIndex(2)
self.widget_stack.widget(2).showNowChattingMessage(self.nick)
def enable(self):
self.widget_stack.setCurrentIndex(2)
self.widget_stack.widget(2).enable()
def resetOrDisable(self):
cur_widget_index = self.widget_stack.currentIndex()
if cur_widget_index == 1:
self.widget_stack.setCurrentIndex(0)
elif cur_widget_index == 2:
self.widget_stack.widget(2).disable()
示例2: PyMultiPageWidget
# 需要导入模块: from PyQt5.QtWidgets import QStackedWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedWidget import currentIndex [as 别名]
class PyMultiPageWidget(QWidget):
currentIndexChanged = pyqtSignal(int)
pageTitleChanged = pyqtSignal(str)
def __init__(self, parent=None):
super(PyMultiPageWidget, self).__init__(parent)
self.comboBox = QComboBox()
# MAGIC
# It is important that the combo box has an object name beginning
# with '__qt__passive_', otherwise, it is inactive in the form editor
# of the designer and you can't change the current page via the
# combo box.
# MAGIC
self.comboBox.setObjectName('__qt__passive_comboBox')
self.stackWidget = QStackedWidget()
self.comboBox.activated.connect(self.setCurrentIndex)
self.layout = QVBoxLayout()
self.layout.addWidget(self.comboBox)
self.layout.addWidget(self.stackWidget)
self.setLayout(self.layout)
def sizeHint(self):
return QSize(200, 150)
def count(self):
return self.stackWidget.count()
def widget(self, index):
return self.stackWidget.widget(index)
@pyqtSlot(QWidget)
def addPage(self, page):
self.insertPage(self.count(), page)
@pyqtSlot(int, QWidget)
def insertPage(self, index, page):
page.setParent(self.stackWidget)
self.stackWidget.insertWidget(index, page)
title = page.windowTitle()
if title == "":
title = "Page %d" % (self.comboBox.count() + 1)
page.setWindowTitle(title)
self.comboBox.insertItem(index, title)
@pyqtSlot(int)
def removePage(self, index):
widget = self.stackWidget.widget(index)
self.stackWidget.removeWidget(widget)
self.comboBox.removeItem(index)
def getPageTitle(self):
return self.stackWidget.currentWidget().windowTitle()
@pyqtSlot(str)
def setPageTitle(self, newTitle):
self.comboBox.setItemText(self.getCurrentIndex(), newTitle)
self.stackWidget.currentWidget().setWindowTitle(newTitle)
self.pageTitleChanged.emit(newTitle)
def getCurrentIndex(self):
return self.stackWidget.currentIndex()
@pyqtSlot(int)
def setCurrentIndex(self, index):
if index != self.getCurrentIndex():
self.stackWidget.setCurrentIndex(index)
self.comboBox.setCurrentIndex(index)
self.currentIndexChanged.emit(index)
pageTitle = pyqtProperty(str, fget=getPageTitle, fset=setPageTitle, stored=False)
currentIndex = pyqtProperty(int, fget=getCurrentIndex, fset=setCurrentIndex)
示例3: FlowDialog
# 需要导入模块: from PyQt5.QtWidgets import QStackedWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedWidget import currentIndex [as 别名]
class FlowDialog(QWidget):
"""
Class for controlling the order of screens in the experiment.
"""
def __init__(self, parent=None):
super(FlowDialog, self).__init__(parent)
self._n_steps = 1 # number of performed steps
self.pages_widget = QStackedWidget()
# create widgets
self.experiment_setup = ExperimentSetup()
self.instructions = InstructionsScreen("./instructions/he-informed-consent.txt")
self.new_user_form = NewUserForm()
self.data_widget = DataWidget()
# add widgets to pages_widget
self.pages_widget.addWidget(self.experiment_setup)
self.pages_widget.addWidget(self.instructions)
self.pages_widget.addWidget(self.new_user_form)
self.pages_widget.addWidget(self.data_widget)
# next button
self.next_button = QPushButton("&Next")
self.next_button_layout = QHBoxLayout()
self.next_button_layout.addStretch(1)
self.next_button_layout.addWidget(self.next_button)
self.next_button.pressed.connect(self.nextPressed)
main_layout = QGridLayout()
# set screen shoulders
main_layout.setRowMinimumHeight(0, 80)
main_layout.setRowMinimumHeight(3, 80)
main_layout.setColumnMinimumWidth(0, 80)
main_layout.setColumnMinimumWidth(2, 80)
main_layout.addWidget(self.pages_widget, 1, 1)
main_layout.addLayout(self.next_button_layout, 2, 1)
self.setLayout(main_layout)
self.pages_widget.setCurrentIndex(0)
def nextPressed(self):
"""
control the order and number of repetitions of the experiment
"""
self.data_widget.count_down_timer.restart_timer() # restart timer
# if on setup screen
if self.pages_widget.currentIndex() == 0:
# get condition index number
condition_index = self.experiment_setup.conditions_combo.currentIndex()
# DEBUGGING:
debug_condition = config.CONDITIONS['a'][condition_index]
print(debug_condition)
self.raise_index()
# welcome screen
elif self.pages_widget.currentIndex() == 1:
self.raise_index()
# if on new_user screen
elif self.pages_widget.currentIndex() == 2:
self.new_user_form.save_results()
self.raise_index()
# if on data screen
elif self.pages_widget.currentIndex() == 3:
if self._n_steps < config.NUM_STEPS:
self.data_widget.add_log_row()
self._n_steps += 1
print("Step number {}".format(self._n_steps)) # DEBUGGING
else:
self.raise_index()
elif self.pages_widget.currentIndex() == 4:
print("That's it") # DEBUGGING
else:
# If reached wrong index
raise RuntimeError("No such index")
def raise_index(self):
current = self.pages_widget.currentIndex()
self.pages_widget.setCurrentIndex(current + 1)
示例4: E5SideBar
# 需要导入模块: from PyQt5.QtWidgets import QStackedWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedWidget import currentIndex [as 别名]
#.........这里部分代码省略.........
self.__actionMethod = None
def isMinimized(self):
"""
Public method to check the minimized state.
@return flag indicating the minimized state (boolean)
"""
return self.__minimized
def isAutoHiding(self):
"""
Public method to check, if the auto hide function is active.
@return flag indicating the state of auto hiding (boolean)
"""
return self.__autoHide
def eventFilter(self, obj, evt):
"""
Public method to handle some events for the tabbar.
@param obj reference to the object (QObject)
@param evt reference to the event object (QEvent)
@return flag indicating, if the event was handled (boolean)
"""
if obj == self.__tabBar:
if evt.type() == QEvent.MouseButtonPress:
pos = evt.pos()
for i in range(self.__tabBar.count()):
if self.__tabBar.tabRect(i).contains(pos):
break
if i == self.__tabBar.currentIndex():
if self.isMinimized():
self.expand()
else:
self.shrink()
return True
elif self.isMinimized():
self.expand()
elif evt.type() == QEvent.Wheel:
if qVersion() >= "5.0.0":
delta = evt.angleDelta().y()
else:
delta = evt.delta()
if delta > 0:
self.prevTab()
else:
self.nextTab()
return True
return QWidget.eventFilter(self, obj, evt)
def addTab(self, widget, iconOrLabel, label=None):
"""
Public method to add a tab to the sidebar.
@param widget reference to the widget to add (QWidget)
@param iconOrLabel reference to the icon or the label text of the tab
(QIcon, string)
@param label the labeltext of the tab (string) (only to be
used, if the second parameter is a QIcon)
"""
if label:
index = self.__tabBar.addTab(iconOrLabel, label)
示例5: _ToolsDock
# 需要导入模块: from PyQt5.QtWidgets import QStackedWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedWidget import currentIndex [as 别名]
#.........这里部分代码省略.........
if not result:
return
index = result.data()
btn = self.__buttons[index]
visible = self.__buttons_visibility.get(btn, False)
self.__buttons_visibility[btn] = not visible
if visible:
btn.hide()
else:
btn.show()
def get_widget_index_by_instance(self, instance):
index = -1
for i, (obj, _) in self.__WIDGETS.items():
if instance == obj:
index = i
break
return index
def execute_file(self):
run_widget = IDE.get_service("run_widget")
index = self.get_widget_index_by_instance(run_widget)
self._show(index)
self.executeFile.emit()
def execute_project(self):
run_widget = IDE.get_service("run_widget")
index = self.get_widget_index_by_instance(run_widget)
self._show(index)
self.executeProject.emit()
def execute_selection(self):
run_widget = IDE.get_service("run_widget")
index = self.get_widget_index_by_instance(run_widget)
self._show(index)
self.executeSelection.emit()
def kill_application(self):
self.stopApplication.emit()
def add_widget(self, display_name, obj):
self._stack_widgets.addWidget(obj)
func = getattr(obj, "install_widget", None)
if isinstance(func, collections.Callable):
func()
def on_button_triggered(self):
# Get button index
button = self.sender()
index = self.__buttons.index(button)
if index == self.current_index() and self._is_current_visible():
self._hide()
else:
self._show(index)
def widget(self, index):
return self.__WIDGETS[index][0]
def _hide(self):
self.__current_widget.setVisible(False)
index = self.current_index()
self.__buttons[index].setChecked(False)
self.widget(index).setVisible(False)
self.hide()
def hide_widget(self, obj):
index = self.get_widget_index_by_instance(obj)
self.set_current_index(index)
self._hide()
def _show(self, index):
widget = self.widget(index)
self.__current_widget = widget
widget.setVisible(True)
widget.setFocus()
self.set_current_index(index)
self.show()
def set_current_index(self, index):
if self.__last_index != -1:
self.__buttons[self.__last_index].setChecked(False)
self.__buttons[index].setChecked(True)
if index != -1:
self._stack_widgets.setCurrentIndex(index)
widget = self.widget(index)
widget.setVisible(True)
self.__last_index = index
def current_index(self):
return self._stack_widgets.currentIndex()
def _is_current_visible(self):
return self.__current_widget and self.__current_widget.isVisible()
def _save_settings(self):
ninja_settings = IDE.ninja_settings()
visible_widget = self.current_index()
if not self.isVisible():
visible_widget = -1
ninja_settings.setValue("tools_dock/widgetVisible", visible_widget)