本文整理汇总了Python中PyQt5.QtWidgets.QStackedWidget.addWidget方法的典型用法代码示例。如果您正苦于以下问题:Python QStackedWidget.addWidget方法的具体用法?Python QStackedWidget.addWidget怎么用?Python QStackedWidget.addWidget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QStackedWidget
的用法示例。
在下文中一共展示了QStackedWidget.addWidget方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AddItemDialog
# 需要导入模块: from PyQt5.QtWidgets import QStackedWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedWidget import addWidget [as 别名]
class AddItemDialog(QDialog):
def __init__(self):
super(AddItemDialog, self).__init__()
self.setupUi(self)
def setupUi(self, AddItemDialog):
self.item_type_picker = QComboBox()
self.item_properties_switch = QStackedWidget()
for form in FORMS:
self.item_type_picker.addItem(form.__name__.split('_')[0],
FORMS.index(form))
self.item_properties_switch.addWidget(form())
self.item_type_picker.currentIndexChanged.connect(
self.item_properties_switch.setCurrentIndex)
self.add_button = QPushButton("Add")
mainLayout = QVBoxLayout(self)
mainLayout.addWidget(self.item_type_picker)
mainLayout.addWidget(self.item_properties_switch, 1)
mainLayout.addWidget(self.add_button)
self.add_button.clicked.connect(self.add_item)
self.setWindowIcon(QIcon(QPixmap('hotel_icon.jpg')))
self.layout().setSizeConstraint(QLayout.SetFixedSize)
self.setWindowTitle("Add Items")
def add_item(self):
self.item_properties_switch.currentWidget().add_button_click()
示例2: SpectateBattle
# 需要导入模块: from PyQt5.QtWidgets import QStackedWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedWidget import addWidget [as 别名]
class SpectateBattle(QWidget):
def __init__(self):
super(SpectateBattle, self).__init__()
self.exitButton = QPushButton('Exit to menu')
self.exitButton.clicked.connect(self.interruptBattle)
self.menu = BotBattleMenu()
self.menu.startButton.clicked.connect(self.startBattle)
self.battle = None
self.stack = QStackedWidget()
self.stack.addWidget(self.menu)
layout = QVBoxLayout()
layout.addWidget(self.stack)
layout.addWidget(self.exitButton)
self.setLayout(layout)
def startBattle(self):
bot1 = game.players.ai.select_bot(self.menu.bot1Level)
bot2 = game.players.ai.select_bot(self.menu.bot2Level)
self.battle = BotBattle(bot1, bot2)
self.stack.addWidget(self.battle)
self.stack.setCurrentWidget(self.battle)
def interruptBattle(self):
if self.battle:
self.battle.interrupt()
示例3: Window
# 需要导入模块: from PyQt5.QtWidgets import QStackedWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedWidget import addWidget [as 别名]
class Window(QWidget):
"""
This part might be removed or included for main window application
"""
def __init__(self, algorithms):
super(Window, self).__init__()
self.stackedWidget = QStackedWidget()
self.orientationCombo = QComboBox()
for category in categories:
pass
for algorithm in algorithms:
self.orientationCombo.addItem(algorithm.get_name())
self.stackedWidget.addWidget(GroupOfSliders(algorithm))
layout = QBoxLayout(QBoxLayout.TopToBottom)
settings_layout = QBoxLayout(QBoxLayout.TopToBottom)
settings_layout.addWidget(self.stackedWidget)
select_layout = QBoxLayout(QBoxLayout.TopToBottom)
select_layout.addWidget(self.orientationCombo)
layout.addItem(settings_layout)
layout.addItem(select_layout)
self.setLayout(layout)
self.setWindowTitle(algorithm.get_name() + " Settings")
示例4: FormComboWidget
# 需要导入模块: from PyQt5.QtWidgets import QStackedWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedWidget import addWidget [as 别名]
class FormComboWidget(QWidget):
def __init__(self, datalist, comment="", parent=None):
QWidget.__init__(self, parent)
layout = QVBoxLayout()
self.setLayout(layout)
self.combobox = QComboBox()
layout.addWidget(self.combobox)
self.stackwidget = QStackedWidget(self)
layout.addWidget(self.stackwidget)
self.combobox.currentIndexChanged[int].connect(self.stackwidget,setCurrentIndex)
self.widgetlist = []
for data, title, comment in datalist:
self.combobox.addItem(title)
widget = FormWidget(data, comment=comment, parent=self)
self.stackwidget.addWidget(widget)
self.widgetlist.append(widget)
def setup(self):
for widget in self.widgetlist:
widget.setup()
def get(self):
return [ widget.get() for widget in self.widgetlist]
示例5: Window
# 需要导入模块: from PyQt5.QtWidgets import QStackedWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedWidget import addWidget [as 别名]
class Window(QWidget):
def __init__(self, all_algorithms):
super(Window, self).__init__()
self.stackedWidget = QStackedWidget()
for item in algorithms:
widget = GuiElement(item)
self.stackedWidget.addWidget(widget)
layout = QHBoxLayout()
layout.addWidget(self.stackedWidget)
self.setLayout(layout)
self.setWindowTitle("Algorithm Settings")
示例6: Window
# 需要导入模块: from PyQt5.QtWidgets import QStackedWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedWidget import addWidget [as 别名]
class Window(QWidget):
def __init__(self, title):
super(Window, self).__init__()
self.horizontalSliders = SlidersGroup(title)
self.stackedWidget = QStackedWidget()
self.stackedWidget.addWidget(self.horizontalSliders)
layout = QHBoxLayout()
layout.addWidget(self.stackedWidget)
self.setLayout(layout)
self.setWindowTitle("Algorithm Settings: ")
示例7: initUI
# 需要导入模块: from PyQt5.QtWidgets import QStackedWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedWidget import addWidget [as 别名]
def initUI(self):
# create menus
menu.GuiMenu()
menu.WidgetMenu()
menu.SettingsMenu()
menu.LoggingMenu()
# main layout
mainVLayout = QVBoxLayout()
elementHLayouts = []
# top element: toolbar, status
t = QLabel("Toolbar")
s = QLabel("Status")
toolbarStatusHLayout = QHBoxLayout()
toolbarStatusHLayout.addWidget(t)
toolbarStatusHLayout.addWidget(s)
elementHLayouts.append(toolbarStatusHLayout)
# mid element: menu buttons
menubuttonsHLayout = QHBoxLayout()
stackedButtonsWidget = QStackedWidget()
buttonGroup = QButtonGroup(self)
buttonGroup.setExclusive(True)
for m in menu.Menu.menus:
btn = QPushButton(m.name)
btn.setCheckable(True)
btn.pressed.connect(lambda m=m: stackedButtonsWidget.setCurrentWidget(m))
menubuttonsHLayout.addWidget(btn)
buttonGroup.addButton(btn)
stackedButtonsWidget.addWidget(m)
elementHLayouts.append(menubuttonsHLayout)
# bot element: menu specific widgets
menuwidgetsHLayout = QHBoxLayout()
menuwidgetsHLayout.addWidget(stackedButtonsWidget)
elementHLayouts.append(menuwidgetsHLayout)
# click first button for defined initial state
if len(buttonGroup.buttons()) > 0:
buttonGroup.buttons()[0].click()
for l in elementHLayouts:
mainVLayout.addLayout(l)
self.setLayout(mainVLayout)
示例8: MultiPlayer
# 需要导入模块: from PyQt5.QtWidgets import QStackedWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedWidget import addWidget [as 别名]
class MultiPlayer(QWidget):
def __init__(self):
super(MultiPlayer, self).__init__()
self.exitButton = QPushButton('Exit to menu')
self.exitButton.clicked.connect(self.exit)
self.menu = MultiPlayerMenu()
self.menu.connectButton.clicked.connect(self.connect)
self.menu.hostButton.clicked.connect(self.host)
self.menu.hotseatButton.clicked.connect(self.hotseat)
self.stack = QStackedWidget()
self.stack.addWidget(self.menu)
layout = QVBoxLayout()
layout.addWidget(self.stack)
layout.addWidget(self.exitButton)
self.setLayout(layout)
self.clientGame = None
self.serverGame = None
self.hotseatGame = None
def host(self):
name = self.menu.nameField.text()
port = self.menu.portSpinBox.value()
self.serverGame = ServerGame(name, port)
self.showGame(self.serverGame)
def connect(self):
name = self.menu.nameField.text()
ip = self.menu.ipField.text()
port = self.menu.portSpinBox.value()
self.clientGame = ClientGame(name, ip, port)
self.showGame(self.clientGame)
def hotseat(self):
self.hotseatGame = HotSeatGame()
self.showGame(self.hotseatGame)
def showGame(self, game):
self.stack.addWidget(game)
self.stack.setCurrentWidget(game)
def exit(self):
self.stack.setCurrentWidget(self.menu)
if self.serverGame:
self.serverGame.end()
if self.clientGame:
self.clientGame.end()
示例9: __init__
# 需要导入模块: from PyQt5.QtWidgets import QStackedWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedWidget import addWidget [as 别名]
def __init__(self, ref_templates, parent=None):
super().__init__(parent)
# Variables sections.
# NB: Sorted.
self._types = ["book", "bookSection", "conferencePaper", "document",
"forumPost", "journalArticle", "patent", "report",
"thesis", "webpage"]
templates_subset = OrderedDict([(k, v) for k, v in ref_templates.items()
if k in self._types])
# Own configuration section.
# TODO Better layout configuration.
self.setMinimumSize(QSize(800, 1000))
# Widgets section.
# TODO Prevent edition of the reference type for an existing reference?
self._types_edit = QComboBox()
self._types_edit.addItems(self._types)
self._types_widgets = self._templates_widgets(templates_subset)
types_forms = self._templates_forms(self._types_widgets)
forms_stack = QStackedWidget()
for x in types_forms:
forms_stack.addWidget(x)
# NB: The first button with the accept role is made the default button.
ok_cancel = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
# Layouts section.
layout = QFormLayout()
layout.addRow(self.ITEM_TYPE_FIELD + ":", self._types_edit)
layout.addRow(forms_stack)
layout.addRow(ok_cancel)
# NB: Don't use AllNonFixedFieldsGrow because it expands the QComboBox.
layout.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow)
utils.configure_form_layout(layout)
self.setLayout(layout)
# Signals section.
self._types_edit.currentIndexChanged.connect(forms_stack.setCurrentIndex)
ok_cancel.accepted.connect(self.accept)
ok_cancel.rejected.connect(self.reject)
示例10: addApplet
# 需要导入模块: from PyQt5.QtWidgets import QStackedWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedWidget import addWidget [as 别名]
def addApplet(self, appletId: int, applet) -> None:
"""
Adds applet to toolbox if it is available in interactive mode
"""
if applet.interactive:
# We need new id before we added item, to handle currentChangedSignal
newToolbarId = self._toolbox.count()
self._toolbarIdByAppletId[appletId] = newToolbarId
self._appletIdByToolbarId[newToolbarId] = appletId
widget = applet.getMultiLaneGui().appletDrawer()
assert isinstance(widget, QWidget), f"Not a widget: {widget}"
stackedWidget = QStackedWidget()
stackedWidget.addWidget(widget)
self._toolbox.addItem(stackedWidget, applet.name)
else:
self._toolbarIdByAppletId[appletId] = None
示例11: MainWindow
# 需要导入模块: from PyQt5.QtWidgets import QStackedWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedWidget import addWidget [as 别名]
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.centralWidget = QStackedWidget()
self.setCentralWidget(self.centralWidget)
startWidget = StartWidget(self)
self.centralWidget.addWidget(startWidget)
self.setWindowTitle("Mountain King")
self.resize(210, 50)
def host(self):
hostWidget = HostWidget(self)
self.centralWidget.addWidget(hostWidget)
self.centralWidget.setCurrentWidget(hostWidget)
self.setWindowTitle("Hosting Mountain King")
self.resize(255, 50)
def join(self):
joinWidget = JoinWidget(self)
self.centralWidget.addWidget(joinWidget)
self.centralWidget.setCurrentWidget(joinWidget)
self.setWindowTitle("Joining Mountain King")
self.resize(255, 50)
示例12: MainGame
# 需要导入模块: from PyQt5.QtWidgets import QStackedWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedWidget import addWidget [as 别名]
class MainGame(QWidget):
def __init__(self):
super(MainGame, self).__init__()
self.menu = MainGameMenu()
self.menu.singlePlayerButton.clicked.connect(self.startSinglePlayer)
self.menu.multiPlayerButton.clicked.connect(self.startMultiPlayer)
self.menu.spectateButton.clicked.connect(self.startSpectateBattle)
self.stack = QStackedWidget()
self.stack.addWidget(self.menu)
layout = QVBoxLayout()
layout.addWidget(self.stack)
self.setLayout(layout)
self.setWindowTitle('Ultimate tic-tac-toe')
self.resize(400, 200)
self.singlePlayer = None
self.multiPlayer = None
self.spectate = None
self.showMenu()
def showMenu(self):
self.stack.setCurrentWidget(self.menu)
def startSinglePlayer(self):
self.singlePlayer = SinglePlayer()
self.singlePlayer.exitButton.clicked.connect(self.showMenu)
self.stack.addWidget(self.singlePlayer)
self.stack.setCurrentWidget(self.singlePlayer)
def startMultiPlayer(self):
if not self.multiPlayer:
self.multiPlayer = MultiPlayer()
self.multiPlayer.exitButton.clicked.connect(self.showMenu)
self.stack.addWidget(self.multiPlayer)
self.stack.setCurrentWidget(self.multiPlayer)
def startSpectateBattle(self):
self.spectate = SpectateBattle()
self.spectate.exitButton.clicked.connect(self.showMenu)
self.stack.addWidget(self.spectate)
self.stack.setCurrentWidget(self.spectate)
示例13: QChatTab
# 需要导入模块: from PyQt5.QtWidgets import QStackedWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedWidget import addWidget [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()
示例14: E5SideBar
# 需要导入模块: from PyQt5.QtWidgets import QStackedWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedWidget import addWidget [as 别名]
class E5SideBar(QWidget):
"""
Class implementing a sidebar with a widget area, that is hidden or shown,
if the current tab is clicked again.
"""
Version = 1
North = 0
East = 1
South = 2
West = 3
def __init__(self, orientation=None, delay=200, parent=None):
"""
Constructor
@param orientation orientation of the sidebar widget (North, East,
South, West)
@param delay value for the expand/shrink delay in milliseconds
(integer)
@param parent parent widget (QWidget)
"""
super(E5SideBar, self).__init__(parent)
self.__tabBar = QTabBar()
self.__tabBar.setDrawBase(True)
self.__tabBar.setShape(QTabBar.RoundedNorth)
self.__tabBar.setUsesScrollButtons(True)
self.__tabBar.setDrawBase(False)
self.__stackedWidget = QStackedWidget(self)
self.__stackedWidget.setContentsMargins(0, 0, 0, 0)
self.__autoHideButton = QToolButton()
self.__autoHideButton.setCheckable(True)
self.__autoHideButton.setIcon(
UI.PixmapCache.getIcon("autoHideOff.png"))
self.__autoHideButton.setChecked(True)
self.__autoHideButton.setToolTip(
self.tr("Deselect to activate automatic collapsing"))
self.barLayout = QBoxLayout(QBoxLayout.LeftToRight)
self.barLayout.setContentsMargins(0, 0, 0, 0)
self.layout = QBoxLayout(QBoxLayout.TopToBottom)
self.layout.setContentsMargins(0, 0, 0, 0)
self.layout.setSpacing(0)
self.barLayout.addWidget(self.__autoHideButton)
self.barLayout.addWidget(self.__tabBar)
self.layout.addLayout(self.barLayout)
self.layout.addWidget(self.__stackedWidget)
self.setLayout(self.layout)
# initialize the delay timer
self.__actionMethod = None
self.__delayTimer = QTimer(self)
self.__delayTimer.setSingleShot(True)
self.__delayTimer.setInterval(delay)
self.__delayTimer.timeout.connect(self.__delayedAction)
self.__minimized = False
self.__minSize = 0
self.__maxSize = 0
self.__bigSize = QSize()
self.splitter = None
self.splitterSizes = []
self.__hasFocus = False
# flag storing if this widget or any child has the focus
self.__autoHide = False
self.__tabBar.installEventFilter(self)
self.__orientation = E5SideBar.North
if orientation is None:
orientation = E5SideBar.North
self.setOrientation(orientation)
self.__tabBar.currentChanged[int].connect(
self.__stackedWidget.setCurrentIndex)
e5App().focusChanged[QWidget, QWidget].connect(self.__appFocusChanged)
self.__autoHideButton.toggled[bool].connect(self.__autoHideToggled)
def setSplitter(self, splitter):
"""
Public method to set the splitter managing the sidebar.
@param splitter reference to the splitter (QSplitter)
"""
self.splitter = splitter
self.splitter.splitterMoved.connect(self.__splitterMoved)
self.splitter.setChildrenCollapsible(False)
index = self.splitter.indexOf(self)
self.splitter.setCollapsible(index, False)
def __splitterMoved(self, pos, index):
"""
Private slot to react on splitter moves.
@param pos new position of the splitter handle (integer)
@param index index of the splitter handle (integer)
"""
if self.splitter:
#.........这里部分代码省略.........
示例15: AppSettings
# 需要导入模块: from PyQt5.QtWidgets import QStackedWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedWidget import addWidget [as 别名]
class AppSettings(QDialog):
SettingsWidgets = []
def __init__(self, conf, **kwargs):
super().__init__(**kwargs)
self.conf = conf
self.setWindowTitle('LiSP preferences')
self.setWindowModality(QtCore.Qt.ApplicationModal)
self.setMaximumSize(635, 530)
self.setMinimumSize(635, 530)
self.resize(635, 530)
self.listWidget = QListWidget(self)
self.listWidget.setGeometry(QtCore.QRect(5, 10, 185, 470))
self.sections = QStackedWidget(self)
self.sections.setGeometry(QtCore.QRect(200, 10, 430, 470))
for widget in self.SettingsWidgets:
widget = widget(QtCore.QSize(430, 465), self)
widget.set_configuration(self.conf)
self.listWidget.addItem(widget.NAME)
self.sections.addWidget(widget)
if len(self.SettingsWidgets) > 0:
self.listWidget.setCurrentRow(0)
self.listWidget.currentItemChanged.connect(self._change_page)
self.dialogButtons = QDialogButtonBox(self)
self.dialogButtons.setGeometry(10, 495, 615, 30)
self.dialogButtons.setStandardButtons(QDialogButtonBox.Cancel |
QDialogButtonBox.Ok)
self.dialogButtons.rejected.connect(self.reject)
self.dialogButtons.accepted.connect(self.accept)
def get_configuraton(self):
conf = {}
for n in range(self.sections.count()):
widget = self.sections.widget(n)
newconf = widget.get_configuration()
deep_update(conf, newconf)
return conf
@classmethod
def register_settings_widget(cls, widget):
if widget not in cls.SettingsWidgets:
cls.SettingsWidgets.append(widget)
@classmethod
def unregister_settings_widget(cls, widget):
if widget not in cls.SettingsWidgets:
cls.SettingsWidgets.remove(widget)
def _change_page(self, current, previous):
if not current:
current = previous
self.sections.setCurrentIndex(self.listWidget.row(current))