[Interest] PySide2 : Adding widget to a QVBoxLayout in a QScrollArea

Nicholas Yue yue.nicholas at gmail.com
Tue Jul 13 06:30:20 CEST 2021


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/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20210712/c48ed6d7/attachment.html>


More information about the Interest mailing list