本文整理汇总了Python中PyQt5.QtWidgets.QStackedLayout.indexOf方法的典型用法代码示例。如果您正苦于以下问题:Python QStackedLayout.indexOf方法的具体用法?Python QStackedLayout.indexOf怎么用?Python QStackedLayout.indexOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QStackedLayout
的用法示例。
在下文中一共展示了QStackedLayout.indexOf方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Preferences
# 需要导入模块: from PyQt5.QtWidgets import QStackedLayout [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedLayout import indexOf [as 别名]
class Preferences(QDialog):
#
configuration = {}
weight = 0
#
savePreferences = pyqtSignal()
#
def __init__(self, parent=None):
super(Preferences, self).__init__(parent, Qt.Dialog)
self.setWindowTitle(translations.TR_PREFERENCES_TITLE)
self.setMinimumSize(QSize(900, 600))
vbox = QVBoxLayout(self)
hbox = QHBoxLayout()
vbox.setContentsMargins(0, 0, 5, 5)
hbox.setContentsMargins(0, 0, 0, 0)
#
self.tree = QTreeWidget()
self.tree.header().setHidden(True)
self.tree.setSelectionMode(QTreeWidget.SingleSelection)
self.tree.setAnimated(True)
self.tree.header().setHorizontalScrollMode(
QAbstractItemView.ScrollPerPixel)
self.tree.header().setSectionResizeMode(0, QHeaderView.ResizeToContents)
self.tree.header().setStretchLastSection(False)
self.tree.setFixedWidth(200)
self.stacked = QStackedLayout()
hbox.addWidget(self.tree)
hbox.addLayout(self.stacked)
vbox.addLayout(hbox)
#
hbox_footer = QHBoxLayout()
self._btnSave = QPushButton(translations.TR_SAVE)
self._btnCancel = QPushButton(translations.TR_CANCEL)
hbox_footer.addSpacerItem(QSpacerItem(1, 0, QSizePolicy.Expanding))
hbox_footer.addWidget(self._btnCancel)
hbox_footer.addWidget(self._btnSave)
vbox.addLayout(hbox_footer)
#
self.tree.itemSelectionChanged.connect(self._change_current)
self._btnCancel.clicked['bool'].connect(self.close)
self._btnSave.clicked['bool'].connect(self._save_preferences)
#
self.load_ui()
self.tree.setCurrentItem(self.tree.topLevelItem(0))
#
def _save_preferences(self):
self.savePreferences.emit()
self.close()
#
def load_ui(self):
sections = sorted(
list(Preferences.configuration.keys()),
key=lambda item: Preferences.configuration[item]['weight'])
for section in sections:
text = Preferences.configuration[section]['text']
Widget = Preferences.configuration[section]['widget']
widget = Widget(self)
area = QScrollArea()
area.setWidgetResizable(True)
area.setWidget(widget)
self.stacked.addWidget(area)
index = self.stacked.indexOf(area)
item = QTreeWidgetItem([text])
item.setData(0, Qt.UserRole, index)
self.tree.addTopLevelItem(item)
#
#Sort Item Children
subcontent = Preferences.configuration[section].get(
'subsections', {})
subsections = sorted(list(subcontent.keys()),
key=lambda item: subcontent[item]['weight'])
for sub in subsections:
text = subcontent[sub]['text']
Widget = subcontent[sub]['widget']
widget = Widget(self)
area = QScrollArea()
area.setWidgetResizable(True)
area.setWidget(widget)
self.stacked.addWidget(area)
index = self.stacked.indexOf(area)
subitem = QTreeWidgetItem([text])
subitem.setData(0, Qt.UserRole, index)
item.addChild(subitem)
#
self.tree.expandAll()
#
def _change_current(self):
item = self.tree.currentItem()
index = item.data(0, Qt.UserRole)
self.stacked.setCurrentIndex(index)
#
@classmethod
def register_configuration(cls, section, widget, text, weight=None,
subsection=None):
if weight is None:
Preferences.weight += 1
weight = Preferences.weight
if not subsection:
Preferences.configuration[section] = {'widget': widget,
'weight': weight,
#.........这里部分代码省略.........
示例2: Preferences
# 需要导入模块: from PyQt5.QtWidgets import QStackedLayout [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedLayout import indexOf [as 别名]
class Preferences(QDialog):
configuration = {}
weight = 0
# Signals
savePreferences = pyqtSignal()
def __init__(self, parent=None):
super().__init__(parent, Qt.Dialog)
self.setWindowTitle(translations.TR_PREFERENCES_TITLE)
self.setMinimumSize(900, 650)
box = QVBoxLayout(self)
box.setContentsMargins(3, 3, 3, 3)
self.setAutoFillBackground(True)
# Header
self._header_label = QLabel("")
header_font = self._header_label.font()
header_font.setBold(True)
header_font.setPointSize(header_font.pointSize() + 4)
self._header_label.setFont(header_font)
hbox = QHBoxLayout()
hbox.setContentsMargins(0, 0, 0, 0)
self.tree = QTreeWidget()
self.tree.header().setHidden(True)
self.tree.setSelectionMode(QTreeWidget.SingleSelection)
self.tree.setAnimated(True)
self.tree.header().setSectionResizeMode(
0, QHeaderView.ResizeToContents)
self.tree.setFixedWidth(200)
hbox.addWidget(self.tree)
self.stacked = QStackedLayout()
header_layout = QVBoxLayout()
header_layout.setContentsMargins(0, 0, 0, 0)
header_layout.addWidget(self._header_label)
header_layout.addLayout(self.stacked)
hbox.addLayout(header_layout)
box.addLayout(hbox)
# Footer buttons
button_box = QDialogButtonBox(
QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
box.addWidget(button_box)
# Connections
button_box.rejected.connect(self.close)
button_box.accepted.connect(self._save_preferences)
self.tree.selectionModel().currentRowChanged.connect(
self._change_current)
self.load_ui()
@pyqtSlot()
def _save_preferences(self):
self.savePreferences.emit()
self.close()
def load_ui(self):
sections = sorted(
Preferences.configuration.keys(),
key=lambda item: Preferences.configuration[item]['weight'])
for section in sections:
text = Preferences.configuration[section]['text']
Widget = Preferences.configuration[section]['widget']
widget = Widget(self)
area = QScrollArea()
area.setWidgetResizable(True)
area.setWidget(widget)
self.stacked.addWidget(area)
index = self.stacked.indexOf(area)
item = QTreeWidgetItem([text])
item.setData(0, Qt.UserRole, index)
self.tree.addTopLevelItem(item)
# Sort Item Children
subcontent = Preferences.configuration[section].get(
'subsections', {})
subsections = sorted(
subcontent.keys(), key=lambda item: subcontent[item]['weight'])
for sub in subsections:
text = subcontent[sub]['text']
Widget = subcontent[sub]['widget']
widget = Widget(self)
area = QScrollArea()
area.setWidgetResizable(True)
area.setWidget(widget)
self.stacked.addWidget(area)
index = self.stacked.indexOf(area)
subitem = QTreeWidgetItem([text])
subitem.setData(0, Qt.UserRole, index)
item.addChild(subitem)
self.tree.expandAll()
self.tree.setCurrentIndex(self.tree.model().index(0, 0))
def _change_current(self):
item = self.tree.currentItem()
index = item.data(0, Qt.UserRole)
#.........这里部分代码省略.........