def clearLayout(layout: QtWidgets.QLayout) -> None: while layout.count() > 0: item = layout.takeAt(0) if item.layout(): clearLayout(item.layout()) if item.widget(): item.widget().setParent(None)
def metadata_window_cursor_layout(self, layout: QtWidgets.QLayout, cursor: QtGui.QCursor) -> None: try: if layout is None: return r = [] i = layout.count() while i > 0: i -= 1 r.append(i) for i in r: child = layout.itemAt(i) # print(child) if isinstance(child, QtWidgets.QWidgetItem): try: if isinstance(child.widget(), QtWidgets.QPushButton): if child.widget().objectName( ) == 'label_cover_view': continue child.widget().setCursor(cursor) except Exception: traceback.print_exc() elif isinstance(child, QtWidgets.QSpacerItem): '' elif isinstance( child, (QtWidgets.QLayoutItem, QtWidgets.QHBoxLayout, QtWidgets.QVBoxLayout, QtWidgets.QGridLayout)): self.metadata_window_cursor_layout(child, cursor) del child except Exception: traceback.print_exc()
def metadata_window_clear_layout(self, layout: QtWidgets.QLayout) -> None: if layout is None: return r = [] i = layout.count() while i > 0: i -= 1 r.append(i) for i in r: child = layout.itemAt(i) # print(child) if isinstance(child, QtWidgets.QWidgetItem): try: child.widget().setVisible(False) layout.removeWidget(child.widget()) # child.widget().deleteLater() except Exception: traceback.print_exc() elif isinstance(child, QtWidgets.QSpacerItem): layout.removeItem(child) elif isinstance(child, (QtWidgets.QLayoutItem, QtWidgets.QHBoxLayout)): self.metadata_window_clear_layout(child) layout.removeItem(child) del child
def clearLayout(layout: QLayout) -> None: """Used to remove widgets from various layouts""" if layout.count(): while (item := layout.takeAt(0)) is not None: layout.removeItem(item) item.widget().hide() item.widget().deleteLater()
def clearLayout(layout: QtWidgets.QLayout): if layout is None: return for i in reversed(range(layout.count())): item = layout.takeAt(i) if item.widget() is not None: item.widget().deleteLater() else: clearLayout(item.layout())
def clear_layout(layout: QLayout) -> None: if layout is None: return while layout.count(): item = layout.takeAt(0) widget = item.widget() if widget is not None: widget.deleteLater() else: clear_layout(item.layout())
def clear_layout(layout: QLayout) -> None: """Clear the layout off all its components""" if layout is not None: while layout.count(): item = layout.takeAt(0) widget = item.widget() if widget is not None: widget.deleteLater() else: clear_layout(item.layout())
def get_layout_widgets(layout: QLayout) -> Iterator[QWidget]: for i in range(layout.count()): item = layout.itemAt(i) sub_layout = item.layout() if sub_layout: yield from get_layout_widgets(sub_layout) else: widget = item.widget() if widget: yield widget
def delete_children(layout: QtWidgets.QLayout) -> None: """Delete all child layouts and widgets of a layout. This must be done before removing this layout from its parent. """ while layout.count() > 0: child = layout.takeAt(0) if child.widget() is not None: child.widget().deleteLater() elif child.layout() is not None: delete_children(child.layout())
def __init__(self, pane_selectors_layout: QLayout, panes_layout: QStackedLayout, pane: QWidget, *args, **kwargs): super().__init__(*args, **kwargs) self.setProperty('pane-selector', 'true') self.setFlat(panes_layout.currentWidget() != pane) self.setCursor(Qt.PointingHandCursor) self.released.connect(lambda: [ pane_selectors_layout.itemAt(i).widget().setFlat(True) for i in range(0, pane_selectors_layout.count()) ]) self.released.connect(lambda: self.setFlat(False)) self.released.connect(lambda: panes_layout.setCurrentWidget(pane))
def setJSONKwargs(self, setFunction, layout:QtWidgets.QLayout, allowedtype:type): """ Used to convert each row to a settings.Test row Args: setFunction (method): The function belonging to each type in the layout layout (QtWidgets.QLayout): the layout to parse through allowedtype (type): The type of Widget with the layout """ items = [layout.itemAt(i).widget() for i in range(layout.count()) ] for item in items: if not issubclass(type(item),Row): continue setFunction(**item.getKwargs()) return
def clear_layout(layout: QLayout): """ Clear all widgets from a QLayout. :param layout: :return: """ widget_count = layout.count() for i in reversed(range(widget_count)): item = layout.itemAt(i) if isinstance(item, QWidgetItem): item.widget().close() else: clear_layout(item.layout()) # Remove item from layout layout.removeItem(item)
def remove_trailing_spacer_from_layout(layout: QLayout): """ If the last item in the layout is spacer, removes it. :param layout: target layout :return: bool success indicator """ ni = layout.count() if ni < 1: return False ni -= 1 layout_item = layout.itemAt(ni) if layout_item is None: return False spacer_item = layout_item.spacerItem() if spacer_item is not None: layout.removeItem(spacer_item) return True return False
def _remove_widgets_from(self, layout: QLayout) -> None: for index in reversed(range(layout.count())): widget = layout.itemAt(index).widget() layout.removeWidget(widget) widget.setParent(None)
def _unselect_all_widgets_in(self, layout: QLayout) -> None: for index in reversed(range(layout.count())): widget = layout.itemAt(index).widget() widget.clear_selection()
def clear_layout(layout: QLayout): while layout.count(): child = layout.takeAt(0) if child.widget(): child.widget().deleteLater()
def clear_layout(qlayout: QLayout): """Removes all children of a layout.""" for i in reversed(range(qlayout.count())): item = qlayout.itemAt(i) qlayout.removeItem(item) item.widget().deleteLater()
def clear_layout(layout: QtWidgets.QLayout) -> None: for i in reversed(range(layout.count())): layout.itemAt(i).widget().setParent(None)
def widgetsOf(layout: QtWidgets.QLayout): return (layout.itemAt(i).widget() for i in range(layout.count()))
def clear_layout(layout: QLayout) -> None: """ Clear all UnitSpawnInfoWidget in given layout""" while layout.count(): child = layout.takeAt(0) if child.widget(): child.widget().deleteLater()
def remove_layout_items(layout: QLayout): for widget in get_layout_widgets(layout): widget.deleteLater() while layout.count(): item = layout.itemAt(0) layout.removeItem(item)
def clearLayout(layout: QtWidgets.QLayout): for i in reversed(range(layout.count())): widget = layout.itemAt(i).widget() layout.removeWidget(widget) widget.setParent(None) widget.deleteLater()
def clear_layout(layout: QtWidgets.QLayout): """Remove all items from layout""" while layout.count(): item: QtWidgets.QLayoutItem = layout.takeAt(0) widget = item.widget() widget.setParent(None)