I need to add info of students (it looks like a table) to the window. It's done in a function called "addStudentStats" and it's added to a main widget. I was trying to make another widget insert scrollbar, and this widget insert into a main one. But it didn't work. Then i tried to make the whole window scrollable, but i couldn't do it either. If anyone can can write those few lines of code (i think there are few, but don't know which) i would be pleased.
Read here
I've added a scrollbar to my window. The program fills it with data, which goes down the screen, but i cannot scroll
from PyQt5.QtWidgets import QPushButton, QWidget, QLabel,QScrollArea, QApplication, QMainWindow
from PyQt5.QtCore import Qt
import sys
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.uiMain = UIMainTeacher()
self.setUpUI(self)
def setUpUI(self, MainWindow):
MainWindow.setGeometry(50, 50, 400, 450)
MainWindow.setFixedSize(1800, 1000)
MainWindow.setWindowTitle("Login")
self.uiMain = UIMainTeacher()
self.gotoTeacher()
def gotoTeacher(self):
self.uiMain.setupUI(self, type)
self.show()
class UIMainTeacher(object):
def setupUI(self, MainWindow, userId):
MainWindow.setGeometry(50, 50, 400, 450)
MainWindow.setFixedSize(1800, 1000)
MainWindow.setWindowTitle("Main")
self.mainWindow = MainWindow
self.centralwid = QScrollArea(MainWindow)
self.centralwid.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
self.centralwidget = QWidget(self.centralwid)
self.exitButton = QPushButton("Exit", self.centralwid)
self.exitButton.move(1700, 0)
self.CourseLabel = QLabel("No Kourse yet", self.centralwid)
self.CourseLabel.move(900, 20)
self.AddCourseButton = QPushButton('Add Course', self.centralwid)
self.AddCourseButton.move(1700, 25)
self.CourseLabel = QLabel("Course", self.centralwidget)
self.CourseLabel.move(900, 20)
self.AddStudentsButton = QPushButton("Add Students", self.centralwid)
self.AddStudentsButton.move(1700, 100)
self.taskLabel = QLabel("TASKS:", self.centralwidget)
self.taskLabel.move(160, 20)
self.AddTaskButton = QPushButton('Add Task', self.centralwid)
self.AddTaskButton.move(1700, 50)
self.centralwid.setWidget(self.centralwidget)
MainWindow.setCentralWidget(self.centralwid)
x, y = 600, 0
for _ in range(200):
label = QLabel("Test Test", self.centralwid)
label.move(x, y)
y += 50
if __name__ == '__main__':
app = QApplication(sys.argv)
w = MainWindow()
sys.exit(app.exec_())