Hi Nicholas,

QScrollArea manages a single widget.  It provides a default, or you can override it - look at the docs.

So in this case, you could apply the layout and pushbutton to scroll.widget, instead of scroll itself.

Also take out the self.setLayout(vbox) - the layout can only belong to one widget.

Hope that helps,

Tony


On 13/07/2021 2:30 pm, Nicholas Yue wrote:
Hi,

  The QPushButton I added does not stay inside of a scroll area, where am I calling the API wrongly ?

import sys
from PySide2 import QtWidgets, QtCore
class Example(QtWidgets.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
scroll = QtWidgets.QScrollArea()
scroll.setWidgetResizable(True)
vbox = QtWidgets.QVBoxLayout()
vbox.setAlignment(QtCore.Qt.AlignTop)
scroll.setLayout(vbox)
vbox.addStretch(1)
for index in range(20):
vbox.addWidget(QtWidgets.QPushButton('button {}'.format(index)))
self.setLayout(vbox)
self.setGeometry(300, 300, 300, 150)
self.setWindowTitle('Buttons')
self.show()
def main():
app = QtWidgets.QApplication(sys.argv)
ex = Example()
ex.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()

Cheers
--
Nicholas Yue
https://www.linkedin.com/in/nicholasyue/ <https://www.linkedin.com/in/nicholasyue/>

_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest
_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest

Reply via email to