Issue
I am having an issue with the QScrollArea and it resizing my widgets. I want all of my layouts and widgets inside of my scroll area to have a fixed height. If I set scroll.setWidgetResizable(True) it will resize everything according to how many widgets were generated. If I set it equal to False then my widgets will not appear. Here is a sample of my code
container = QtWidgets.QWidget()
list_layout = QtWidgets.QVBoxLayout()
container.setLayout(list_layout)
scroll = QtWidgets.QScrollArea()
scroll.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
scroll.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
scroll.setWidgetResizable(True)
scroll.setWidget(container)
for x in range 10:
product_container = QtWidgets.QFrame()
product_container .setFixedHeight(50)
row = QtWidgets.QHBoxLayout(product_container)
name = QtWidgets.QLabel(y)
cbox = QtWidgets.QCheckBox()
row.addWidget(name)
row.addWidget(cbox)
seperator = QtWidgets.QFrame()
separator.setFrameStyle(QtWidgets.QFrame.HLine | QtWidgets.QFrame.Plain)
list_layout.addWidget(product_container)
list_layout.addWidget(separator)
I tried setting my generated containers for the horizontal layout to have a fixed size, (which does work - if I set the background color it shows the box is smaller around my widgets) but the space in between the horizontal layout and the QFrame line is still random.
My end goal is to have a fixed distance in between my horizontal layout and separator
Solution
If the rows have a fixed height, all you need to do to is add an expandable space to the end of the container's layout, so that the rows are all pushed upwards:
container = QtWidgets.QWidget()
list_layout = QtWidgets.QVBoxLayout()
container.setLayout(list_layout)
...
for x in range(10):
...
list_layout.addWidget(separator)
list_layout.addStretch()
Answered By - ekhumoro
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.