示例#1
0
def hide_items_in_layout(
        layout: QtWidgets.QLayout
):
    """Hides all items within a Qt-layout
    """
    for i in range(layout.count()):
        item = layout.itemAt(i)
        if type(item) == QtWidgets.QWidgetItem:
            item.widget().hide()
示例#2
0
def clear_layout(
        layout: QtWidgets.QLayout
):
    """Clears all widgets within a layout
    """
    while layout.count():
        child = layout.takeAt(0)
        if child.widget() is not None:
            child.widget().deleteLater()
        elif child.layout() is not None:
            clear_layout(child.layout())
示例#3
0
 def insertWidget(layout: QLayout, position: int, widget: QWidget, label: str = ""):
     """Add widget to arbitrary layout at position, with optional label."""
     if position < 0:
         position = layout.count() + position + 1
     if isinstance(layout, QFormLayout):
         layout.insertRow(position, label, widget)
     else:
         layout.insertWidget(position, widget)
         if label:
             label_widget = QLabel(label)
             label_widget.setAlignment(Qt.AlignVCenter | Qt.AlignRight)
             layout.insertWidget(position, label_widget)
示例#4
0
def clearLayout(layout: QLayout) -> None:
    if layout.count() == 0:
        return

    item: QLayoutItem = layout.takeAt(0)
    while item is not None:
        if item.widget() is not None:
            item.widget().deleteLater()
        elif item.layout() is not None:
            item.layout().deleteLater()

        item = layout.takeAt(0)
示例#5
0
def get_widgets_in_layout(
        layout: QtWidgets.QLayout
):
    """Returns a list of all widgets within a layout
    """
    return (layout.itemAt(i) for i in range(layout.count()))