Reuploaded, Pyqt create label in qscrollarea by button

Viewed 22
from PyQt5 import uic, QtWidgets
from PyQt5.QtWidgets import *
from functools import partial
from PyQt5.QtCore import *
import sys
from PyQt5 import QtCore, QtGui, QtWidgets

class Exampleforstack(QMainWindow):
    def __init__(self):
        super(Exampleforstack, self).__init__()
        uic.loadUi('mainui.ui', self)
        self.scrollArea.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) #scrollArea is Qscrollarea
        self.scrollArea.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
        self.Continue.clicked.connect(self.getnews) #qpushbutton


def getnews(self, event):
    lb = QLabel('hjkmlasda')
    lb.setStyleSheet("""
       border-width: 1px;
      border-style: solid;
      border-color:blue;
     """)
    lb.setFixedSize(360, 100)
    self.scrollArea.setWidget(lb)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    mainWindow = Exampleforstack()
    main = Exampleforstack()
    app.exec_()

MY UI

I'm currently facing problem with dynamically create label in qscrollarea. upper code only create label just once and no response after first click. but problem is, result has problem but i don't think code is wrong. am i missing smth? and what should i do to create label in scrollarea by button?

i've also changed self.scrollArea.setWidget(lb) into self.verticalLayout_5.addWidget(lb) but new problem occured, it doesn't scroll neither and also unwanted overlap

0 Answers
Related