I have a class definition that uses a QVBoxLayout ( main_layout) where I have a few buttons.
Beneath that I currently have a ton of group boxes
I’d like to put those items (after the buttons) , inside a QScrollArea, so the buttons stay ‘locked ‘ at the of my UI and the other widgets can be scrolled through
The problem I have is that the QScrollArea only has a ‘setWidget’ function - how do I pass it the entirety of those other widgets ? I don’t want to have to put them in a different class altogether
Eg QScrollArea.setLayout() would be useful here !
I’ve tried putting all those widgets under a new sub_layout QVBoxLayout , I just now need a scroll widget controlling it
Any thoughts ?
main_layout = qw.QVBoxLayout()
self.layout().addLayout(main_layout)
#do it button added to main layout not scroll area
self.run_button = customButton("place between components",parent=self)
self.run_button.setFixedWidth(315)
self.run_button.setFixedHeight(30)
main_layout.addWidget(self.run_button)
#make the scroll area
scrollArea = qw.QScrollArea()
subWidget = qw.QWidget()
subWidget.setContentsMargins(0,0,0,0)
sub_layout = qw.QVBoxLayout()
subWidget.setLayout(sub_layout)
scrollArea.setWidget(subWidget)
#add it to the main layout
main_layout.addWidget(scrollArea)
#all my extra layouts and widgets for options are declared
#pins v layout
pins_main_v_layout = qw.QVBoxLayout()
pins_main_v_layout.setSpacing(4)
pins_main_v_layout.setContentsMargins(2,2,2,2)
#stitching v layout
stitching_main_v_layout = qw.QVBoxLayout()
stitching_main_v_layout.setContentsMargins(2,2,2,2)
#cable v layout
cable_main_v_layout = qw.QVBoxLayout()
cable_main_v_layout.setContentsMargins(2,2,2,2)
#add the options layouts to the scroll area sub widget
sub_layout.addLayout(pins_main_v_layout)
sub_layout.addLayout(stitching_main_v_layout)
sub_layout.addLayout(cable_main_v_layout)
# all the options and further layouts, widgets declared from here
# i include one example below
#PINS
#define the contents pins layout
#main pins box
pins_vbox_group_layout = qw.QVBoxLayout()
pins_vbox_group_layout.setSpacing(4)
self.pins_group_box = qw.QGroupBox('pins')
self.pins_group_box.setAlignment(qc.Qt.AlignHCenter)
self.pins_group_box.setCheckable(True)
pins_main_v_layout.addWidget(self.pins_group_box)
self.pins_group_box.setLayout(pins_vbox_group_layout)
You have to create an intermediate widget where you set the layout and it can be placed in the QScrollArea:
widget = QtWidgets.QWidget()
widget.setContentsMargins(0, 0, 0, 0)
widget.setLayout(sub_layout)
scrollarea.setWidget(widget)