Q
Q
Quiab2020-03-31 11:03:39
Python
Quiab, 2020-03-31 11:03:39

How to setup scrollArea PyQt?

Hello, all morning I’ve been banging my head on the task of making the scroll bar spin, but all attempts are in vain, since I’m far from the result, please tell me how to fix the code below (in the group box, a couple of buttons and a group box will be created and you need to scroll

import sys
from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(378, 368)
        buttons = []
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.groupBox = QtWidgets.QGroupBox(self.centralwidget)
        self.groupBox.setGeometry(QtCore.QRect(120, 80, 141, 151))
        self.groupBox.setObjectName("groupBox")
        for i in range(1,30):
            buttons.append((QtWidgets.QPushButton(self.groupBox), QtWidgets.QPushButton(self.groupBox)))
            buttons[-1][0].setGeometry(QtCore.QRect(10, i*30, 90, 25))
            buttons[-1][0].setObjectName("group_{0}".format(i))
            buttons[-1][1].setGeometry(QtCore.QRect(100, i*30, 20, 25))
            buttons[-1][0].setObjectName("del_{0}".format(i))
        
        scrollArea = QtWidgets.QScrollArea()
        scrollArea.setWidget(self.groupBox)
        
        # self.verticalScrollBar = QtWidgets.QScrollBar(self.groupBox)
        # self.verticalScrollBar.setGeometry(QtCore.QRect(120, 20, 20, 131))
        # self.verticalScrollBar.setOrientation(QtCore.Qt.Vertical)
        # self.verticalScrollBar.setObjectName("verticalScrollBar")
        MainWindow.setCentralWidget(self.centralwidget)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "Имя группы"))
            
class ExampleApp(QtWidgets.QMainWindow, Ui_MainWindow):
    def __init__(self):
        super().__init__()
        self.setupUi(self)

def main():
    app = QtWidgets.QApplication(sys.argv)
    window = ExampleApp()
    window.show()
    app.exec_()

if __name__ == "__main__":
    main()


Attach a light verbal description to the described solution. how to work with these bars - I will be even more grateful. Thanks in advance!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question