nspyre.gui.widgets.layout
Module Contents
Classes
A node in the tree returned by |
Functions
|
Arrange a tree of provided widgets and layouts into corresponding Qt layout |
- class nspyre.gui.widgets.layout.LayoutTreeNode(layout, children)
A node in the tree returned by
tree_layout()
.Children can be accessed with dot notation - see example in
tree_layout()
.- Parameters:
layout (pyqtgraph.Qt.QtWidgets.QLayout) – QLayout object for this node.
children (dict) – Dict with string keys mapped to values of either
QtWidgets.QWidget
,QtWidgets.QLayout
, orLayoutTreeNode
.
- layout
Same as ‘layout’ argument.
- children
Same as ‘children’ argument.
- nspyre.gui.widgets.layout.tree_layout(config)
Arrange a tree of provided widgets and layouts into corresponding Qt layout objects.
Example usage:
from nspyre import tree_layout from pyqtgraph.Qt import QtWidgets class MyWidget(QtWidgets.QWidget): def __init__(self): super().__init__() label1 = QtWidgets.QLabel('Label1') label2 = QtWidgets.QLabel('Label2') label3 = QtWidgets.QLabel('Label3') label4 = QtWidgets.QLabel('Label4') label5 = QtWidgets.QLabel('Label5') label6 = QtWidgets.QLabel('Label6') layout_config = { 'type': QtWidgets.QVBoxLayout, 'l1': label1, 'l2': label2, 'sub_layout': { 'type': QtWidgets.QHBoxLayout, 'l3': label3, 'l4': label4, 'sub_sub_layout': { 'type': QtWidgets.QVBoxLayout, 'l5': label5, 'l6': label6, } } } tree_root = tree_layout(layout_config) self.setLayout(tree_root.layout) print(tree_root.l1.text()) print(tree_root.sub_layout.sub_sub_layout.l5.text())
- Parameters:
config (Dict) – Tree of dictionaries describing the layout structure. Each dictionary (node) must contain a
'type'
key. The value associated with'type'
should be aQtWidgets.QLayout
. All other keys/values should be a string mapping to either aQtWidgets.QLayout
,QtWidgets.QWidget
, or another dictionary with the given structure.- Raises:
ValueError – Invalid arguments.
- Returns:
The layout root node.
- Return type: