Q
Q
Quiab2020-05-07 20:08:23
Python
Quiab, 2020-05-07 20:08:23

How to put a ScrollArea on a GroupBox in PyQt?

Hello, you need to create a window, inside which there will be a GroupBox, in which buttons will be dynamically added
. In case of going beyond the boundaries, I want scroll to appear, but it completely refuses to accept my attempts and be displayed on the screen, at the moment I don’t even imagine than the problem, hope to help, thanks in advance !

# -*- coding: utf-8 -*-
from PyQt5 import QtCore, QtWidgets
import sys

app = QtWidgets.QApplication(sys.argv)
window = QtWidgets.QWidget()
window.setWindowTitle("Scroll")
window.resize(300,700)

mainbox = QtWidgets.QVBoxLayout() # Сюда поместим GroupBox

vbox = QtWidgets.QVBoxLayout() # Для кнопочек
scroll = QtWidgets.QScrollArea() # Скролиться должен GroupBox
group = QtWidgets.QGroupBox("Check Me") # Этот GroupBox

scroll.setWidget(group) # Для этого я передаю его в ScrollArea


for i in range(50): # Накидываем кнопочки
    vbox.addWidget(QtWidgets.QPushButton("button {}".format(i)))

group.setLayout(vbox) # Закидываем область с кнопками в группу 
mainbox.addWidget(group) # Закидываем группу в главный слой 
window.setLayout(mainbox) # Закрепляем главный слой

window.show()
sys.exit(app.exec_())

Answer the question

In order to leave comments, you need to log in

1 answer(s)
1
101-s, 2020-05-07
@101-s

# The GroupBox should scroll a
guess, not exactly: what if we change its size when adding buttons?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question