本文整理汇总了Python中PyQt5.QtWidgets.QSplitter.count方法的典型用法代码示例。如果您正苦于以下问题:Python QSplitter.count方法的具体用法?Python QSplitter.count怎么用?Python QSplitter.count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QSplitter
的用法示例。
在下文中一共展示了QSplitter.count方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: QuadView
# 需要导入模块: from PyQt5.QtWidgets import QSplitter [as 别名]
# 或者: from PyQt5.QtWidgets.QSplitter import count [as 别名]
class QuadView(QWidget):
def __init__(self, parent, view1, view2, view3, view4=None):
QWidget.__init__(self, parent)
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.installEventFilter(self)
self.dockableContainer = []
self.layout = QVBoxLayout()
self.setLayout(self.layout)
self.layout.setContentsMargins(0, 0, 0, 0)
self.layout.setSpacing(0)
self.splitVertical = QSplitter(Qt.Vertical, self)
self.layout.addWidget(self.splitVertical)
self.splitHorizontal1 = QSplitter(Qt.Horizontal, self.splitVertical)
self.splitHorizontal1.setObjectName("splitter1")
self.splitHorizontal2 = QSplitter(Qt.Horizontal, self.splitVertical)
self.splitHorizontal2.setObjectName("splitter2")
self.splitHorizontal1.splitterMoved.connect(self.horizontalSplitterMoved)
self.splitHorizontal2.splitterMoved.connect(self.horizontalSplitterMoved)
self.imageView2D_1 = view1
self.imageView2D_2 = view2
self.imageView2D_3 = view3
self.dock1_ofSplitHorizontal1 = ImageView2DDockWidget(self.imageView2D_1)
self.dock1_ofSplitHorizontal1.connectHud()
self.dockableContainer.append(self.dock1_ofSplitHorizontal1)
self.dock1_ofSplitHorizontal1.onDockButtonClicked.connect(
lambda arg=self.dock1_ofSplitHorizontal1: self.on_dock(arg)
)
self.dock1_ofSplitHorizontal1.onMaxButtonClicked.connect(
lambda arg=self.dock1_ofSplitHorizontal1: self.on_max(arg)
)
self.dock1_ofSplitHorizontal1.onMinButtonClicked.connect(
lambda arg=self.dock1_ofSplitHorizontal1: self.on_min(arg)
)
self.splitHorizontal1.addWidget(self.dock1_ofSplitHorizontal1)
self.dock2_ofSplitHorizontal1 = ImageView2DDockWidget(self.imageView2D_2)
self.dock2_ofSplitHorizontal1.onDockButtonClicked.connect(
lambda arg=self.dock2_ofSplitHorizontal1: self.on_dock(arg)
)
self.dock2_ofSplitHorizontal1.onMaxButtonClicked.connect(
lambda arg=self.dock2_ofSplitHorizontal1: self.on_max(arg)
)
self.dock2_ofSplitHorizontal1.onMinButtonClicked.connect(
lambda arg=self.dock2_ofSplitHorizontal1: self.on_min(arg)
)
self.dock2_ofSplitHorizontal1.connectHud()
self.dockableContainer.append(self.dock2_ofSplitHorizontal1)
self.splitHorizontal1.addWidget(self.dock2_ofSplitHorizontal1)
self.dock1_ofSplitHorizontal2 = ImageView2DDockWidget(self.imageView2D_3)
self.dock1_ofSplitHorizontal2.onDockButtonClicked.connect(
lambda arg=self.dock1_ofSplitHorizontal2: self.on_dock(arg)
)
self.dock1_ofSplitHorizontal2.onMaxButtonClicked.connect(
lambda arg=self.dock1_ofSplitHorizontal2: self.on_max(arg)
)
self.dock1_ofSplitHorizontal2.onMinButtonClicked.connect(
lambda arg=self.dock1_ofSplitHorizontal2: self.on_min(arg)
)
self.dock1_ofSplitHorizontal2.connectHud()
self.dockableContainer.append(self.dock1_ofSplitHorizontal2)
self.splitHorizontal2.addWidget(self.dock1_ofSplitHorizontal2)
self.dock2_ofSplitHorizontal2 = ImageView2DDockWidget(view4)
self.dockableContainer.append(self.dock2_ofSplitHorizontal2)
self.splitHorizontal2.addWidget(self.dock2_ofSplitHorizontal2)
# this is a hack: with 0 ms it does not work...
QTimer.singleShot(250, self._resizeEqual)
def _resizeEqual(self):
if not all([dock.isVisible() for dock in self.dockableContainer]):
return
w, h = (
self.size().width() - self.splitHorizontal1.handleWidth(),
self.size().height() - self.splitVertical.handleWidth(),
)
self.splitVertical.setSizes([h // 2, h // 2])
if self.splitHorizontal1.count() == 2 and self.splitHorizontal2.count() == 2:
# docks = [self.imageView2D_1, self.imageView2D_2, self.imageView2D_3, self.testView4]
docks = []
for splitter in [self.splitHorizontal1, self.splitHorizontal2]:
for i in range(splitter.count()):
docks.append(splitter.widget(i).graphicsView)
w1 = [docks[i].minimumSize().width() for i in [0, 2]]
w2 = [docks[i].minimumSize().width() for i in [1, 3]]
wLeft = max(w1)
wRight = max(w2)
#.........这里部分代码省略.........
示例2: _s_CentralWidget
# 需要导入模块: from PyQt5.QtWidgets import QSplitter [as 别名]
# 或者: from PyQt5.QtWidgets.QSplitter import count [as 别名]
class _s_CentralWidget(QWidget):
###############################################################################
# CentralWidget SIGNALS
###############################################################################
"""
splitterCentralRotated()
"""
splitterCentralRotated = pyqtSignal()
###############################################################################
def __init__(self, parent=None):
super(_s_CentralWidget, self).__init__(parent)
self.parent = parent
#This variables are used to save the splitter sizes before hide
self._splitterMainSizes = None
self._splitterAreaSizes = None
self.lateralPanel = None
hbox = QHBoxLayout(self)
hbox.setContentsMargins(0, 0, 0, 0)
hbox.setSpacing(0)
#Create Splitters to divide the UI in: MainPanel, Explorer, Misc
self._splitterArea = QSplitter(Qt.Horizontal)
self._splitterMain = QSplitter(Qt.Vertical)
#Create scrollbar for follow mode
self.scrollBar = QScrollBar(Qt.Vertical, self)
self.scrollBar.setFixedWidth(20)
self.scrollBar.setToolTip('Follow Mode: Scroll the Editors together')
self.scrollBar.hide()
self.scrollBar.valueChanged[int].connect(self.move_follow_scrolls)
#Add to Main Layout
hbox.addWidget(self.scrollBar)
hbox.addWidget(self._splitterArea)
def insert_central_container(self, container):
self.mainContainer = container
self._splitterMain.insertWidget(0, container)
def insert_lateral_container(self, container):
self.lateralPanel = LateralPanel(container)
self._splitterArea.insertWidget(0, self.lateralPanel)
def insert_bottom_container(self, container):
self.misc = container
self._splitterMain.insertWidget(1, container)
def showEvent(self, event):
#Show Event
QWidget.showEvent(self, event)
#Avoid recalculate the panel sizes if they are already loaded
if self._splitterArea.count() == 2:
return
#Rearrange widgets on Window
self._splitterArea.insertWidget(0, self._splitterMain)
if not event.spontaneous():
self.change_misc_visibility()
if bin(settings.UI_LAYOUT)[-1] == '1':
self.splitter_central_rotate()
if bin(settings.UI_LAYOUT >> 1)[-1] == '1':
self.splitter_misc_rotate()
if bin(settings.UI_LAYOUT >> 2)[-1] == '1':
self.splitter_central_orientation()
qsettings = QSettings(resources.SETTINGS_PATH, QSettings.IniFormat)
#Lists of sizes as list of QVariant- heightList = [QVariant, QVariant]
heightList = list(qsettings.value("window/central/mainSize",
[(self.height() / 3) * 2, self.height() / 3]))
widthList = list(qsettings.value("window/central/areaSize",
[(self.width() / 6) * 5, self.width() / 6]))
self._splitterMainSizes = [int(heightList[0]), int(heightList[1])]
self._splitterAreaSizes = [int(widthList[0]), int(widthList[1])]
#Set the sizes to splitters
#self._splitterMain.setSizes(self._splitterMainSizes)
self._splitterMain.setSizes(self._splitterMainSizes)
self._splitterArea.setSizes(self._splitterAreaSizes)
self.misc.setVisible(
qsettings.value("window/show_misc", False, type=bool))
def change_misc_visibility(self, on_start=False):
if self.misc.isVisible():
self._splitterMainSizes = self._splitterMain.sizes()
self.misc.hide()
widget = self.mainContainer.get_actual_widget()
if widget:
widget.setFocus()
else:
self.misc.show()
self.misc.gain_focus()
def change_main_visibility(self):
if self.mainContainer.isVisible():
self.mainContainer.hide()
else:
self.mainContainer.show()
def change_explorer_visibility(self, force_hide=False):
#.........这里部分代码省略.........
示例3: PanelContainer
# 需要导入模块: from PyQt5.QtWidgets import QSplitter [as 别名]
# 或者: from PyQt5.QtWidgets.QSplitter import count [as 别名]
class PanelContainer(QWidget):
def __init__(self, panelWin):
super(QWidget, self).__init__()
self.panelWindow = panelWin
self.panelCount = 0
self.mainLayout = QGridLayout(self)
self.mainLayout.setContentsMargins(0, 0, 0, 0)
self.splitter = QSplitter(self)
self.containerParent = 0
self.mainLayout.addWidget(self.splitter, 0, 0)
def splitter(self):
return self.splitter
def addPanel(self, panel=None):
if panel:
panel.setParent(self)
panel.setContainer(self)
self.splitter.addWidget(panel)
self.panelCount += 1
self.updatePanelSignals(panel)
else:
panel = self.createPanel()
self.splitter.addWidget(panel)
return panel
def addPanelSplit(self, panel, direction):
panel = PanelWidget(self) if 0 else panel
# Store original size
origSize = panel.size()
# reparent the panel
panel.setParent(self)
panel.setContainer(self)
# set orientation and add the panel
self.splitter.setOrientation(direction)
self.splitter.addWidget(panel)
# add another panel for split
panel = self.createPanel()
self.splitter.addWidget(panel)
sizes = list()
origSize *= 0.5
if direction == Qt.Horizontal:
sizes.append(origSize.width())
sizes.append(origSize.width())
else:
sizes.append(origSize.height())
sizes.append(origSize.height())
self.splitter.setSizes(sizes)
self.panelCount += 1
def addContainer(self, child):
child = PanelContainer(self) if 0 else child
self.splitter.addWidget(child)
child.setParentContainer(self)
def insertContainer(self, child, index):
child = PanelContainer(self) if 0 else child
self.splitter.insertWidget(index, child)
child.setParentContainer(self)
def setParentContainer(self, parent):
self.containerParent = parent
def parentContainer(self):
return self.containerParent
def childContainers(self):
# childContainers = list()
# for index in range(0, self.splitter.count()):
# container = self.splitter.widget(index)
# if container:
# childContainers.append(container)
return self.sortedChildren()
def panels(self):
# panels = list()
# for index in range(0, self.splitter.count()):
# panel = self.splitter.widget(index)
# if panel:
# panels.append(panel)
return self.sortedChildren()
def sortedChildren(self):
return (self.splitter.widget(index) for index in range(self.splitter.count()))
def numberOfPanels(self):
return self.panelCount
def createPanel(self):
panel = PanelWidget(self)
#.........这里部分代码省略.........
示例4: MainWindow
# 需要导入模块: from PyQt5.QtWidgets import QSplitter [as 别名]
# 或者: from PyQt5.QtWidgets.QSplitter import count [as 别名]
#.........这里部分代码省略.........
self.addAction(quit_action)
self.vertical_splitter = QSplitter(Qt.Vertical, self)
self.setCentralWidget(self.vertical_splitter)
self.load_central_widget()
self.file_menu = self.menuBar().addMenu(self.tr('&File'))
self.file_menu.addAction(quit_action)
self.file_menu.addSeparator()
self.module_menu = self.menuBar().addMenu(self.tr('&Modules'))
self.module_menu.addAction(reload_modules_action)
self.module_menu.addSeparator()
Alter.invoke_all('main_window_init', self)
#restore main window state
size = ModuleManager.core['settings'].Settings.value(
self.KEY_WINDOW_SIZE, QSize(600, 400))
maximized = ModuleManager.core['settings'].Settings.value(
self.KEY_WINDOW_MAXIMIZED, False)
position = ModuleManager.core['settings'].Settings.value(
self.KEY_WINDOW_POSITION, QPoint(0,0))
if maximized == 'true':
self.showMaximized()
else:
self.resize(size)
self.move(position)
def closeEvent(self, event):
self.on_quit()
def save_state(self):
ModuleManager.core['settings'].Settings.set_value(
self.KEY_WINDOW_SIZE, self.size())
ModuleManager.core['settings'].Settings.set_value(
self.KEY_WINDOW_MAXIMIZED, self.isMaximized())
ModuleManager.core['settings'].Settings.set_value(
self.KEY_WINDOW_POSITION, self.pos())
ModuleManager.core['settings'].Settings.set_value(
self.KEY_H_SPLITTER_STATE, self.horizontal_splitter.saveState())
def on_quit(self):
self.save_state()
self.close()
def load_central_widget(self):
self.populate_central_widget()
self.connect_widgets()
def populate_central_widget(self):
self.vertical_widgets = collections.OrderedDict()
self.horizontal_splitter = QSplitter(
Qt.Horizontal, self.vertical_splitter)
self.horizontal_widgets = collections.OrderedDict()
self.vertical_widgets["horizontal_splitter"] = self.horizontal_splitter
Alter.invoke_all(
'main_window_add_vertical_widget',
self.vertical_widgets,
self
)
for widget in self.vertical_widgets.values():
self.vertical_splitter.addWidget(widget)
Alter.invoke_all(
'main_window_add_horizontal_widget',
self.horizontal_widgets,
self.vertical_splitter
)
for widget in self.horizontal_widgets.values():
self.horizontal_splitter.addWidget(widget)
#restore horizontal splitter state
state = ModuleManager.core['settings'].Settings.value(
self.KEY_H_SPLITTER_STATE,
None
)
if state:
self.horizontal_splitter.restoreState(state)
def connect_widgets(self):
Alter.invoke_all(
'main_window_connect_widgets',
self.vertical_widgets,
self.horizontal_widgets
)
def reload_central_widget(self):
self.save_state()
for index in range(self.vertical_splitter.count()):
widget = self.vertical_splitter.widget(index)
widget.hide()
widget.setParent(None)
del widget
Alter.clear()
ModuleManager.reload_all_modules('core')
ModuleManager.reload_all_modules('custom')
self.load_central_widget()
示例5: MainWindow
# 需要导入模块: from PyQt5.QtWidgets import QSplitter [as 别名]
# 或者: from PyQt5.QtWidgets.QSplitter import count [as 别名]
#.........这里部分代码省略.........
self.KEY_WINDOW_SIZE, self.size())
ModuleManager.core['settings'].Settings.set_value(
self.KEY_WINDOW_MAXIMIZED, self.isMaximized())
ModuleManager.core['settings'].Settings.set_value(
self.KEY_WINDOW_POSITION, self.pos())
ModuleManager.core['settings'].Settings.set_value(
self.KEY_H_SPLITTER_STATE, self.horizontal_splitter.saveState())
def on_quit(self):
self.save_state()
self.close()
def load_central_widget(self):
self.populate_central_widget()
self.connect_widgets()
def populate_central_widget(self):
self.vertical_widgets = collections.OrderedDict()
self.horizontal_splitter = QSplitter(
Qt.Horizontal, self.vertical_splitter)
self.horizontal_widgets = collections.OrderedDict()
self.vertical_widgets["horizontal_splitter"] = self.horizontal_splitter
Alter.invoke_all(
'main_window_add_vertical_widget',
self.vertical_widgets,
self
)
for widget in self.vertical_widgets.values():
self.vertical_splitter.addWidget(widget)
Alter.invoke_all(
'main_window_add_horizontal_widget',
self.horizontal_widgets,
self.vertical_splitter
)
for widget in self.horizontal_widgets.values():
self.horizontal_splitter.addWidget(widget)
#restore horizontal splitter state
state = ModuleManager.core['settings'].Settings.value(
self.KEY_H_SPLITTER_STATE,
None
)
if state:
self.horizontal_splitter.restoreState(state)
def connect_widgets(self):
Alter.invoke_all(
'main_window_connect_widgets',
self.vertical_widgets,
self.horizontal_widgets
)
def reload_central_widget(self):
self.save_state()
for index in range(self.vertical_splitter.count()):
widget = self.vertical_splitter.widget(index)
widget.hide()
widget.setParent(None)
del widget
Alter.clear()
ModuleManager.reload_all_modules('core')
ModuleManager.reload_all_modules('custom')
self.load_central_widget()
def add_action(self, name, callback, **kwargs):
"""
Ajoute une action au context menu et au widget lui même.
Créer une fonction à la volé pour fournir des arguments aux fonctions
de rappel.
"""
action = QAction(name, self)
if 'icon' in kwargs:
action.setIcon(kwargs['icon'])
if 'shortcut' in kwargs:
action.setShortcut(kwargs['shortcut'])
action.setShortcutContext(Qt.WidgetWithChildrenShortcut)
action.triggered.connect(self.__wrapper(callback, **kwargs))
self.addAction(action)
if 'menu' in kwargs:
kwargs['menu'].addAction(action)
def add_separator(self, menu):
"""Simple abstraction of self.context_menu.addSeparator()"""
menu.addSeparator()
def __wrapper(self, callback, **kwargs):
def __new_function():
"""
__new_function représente la forme de tous les callbacks connecté
à une action pour pouvoir utiliser les raccourcis en même temps que
le menu contextuel.
"""
args = [
kwargs['instance'] if 'instance' in kwargs else self
]
callback(*args)
return __new_function