0

So, I've been having issues working with PyQt5 and Scroll areas/ widgets/ frames. I'm an amateur programmer and I'm doing this for the office I'm working for. I anyone could help me, areas with "** **" are where the central widget and the scroll area were created. Above the scroll area should be a menu I created (like on the first picture). Somehow the scroll area is overlapping the menu above.

If I add this amount of labels, everything is ok:

If I add this amount of labels, everything is ok

Now, if I add more, it shows over the menu bar:

Now, if I add more, it shows over the menu bar

If anyone can help me, here's the code

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtGui import QIcon, QPixmap, QFont
from AddProcessWindow import Ui_AddProcessWindow
from P_Label import ProcessObj


class Ui_OtherWindow(object):
    #
    # STYLES
    #



    #
    # FUNCTIONS
    #

    def refresh(self):
        self.window = QtWidgets.QMainWindow()
        self.ui = Ui_OtherWindow()
        self.ui.setupUi(self.window)
        self.window.show()


    def addProcessLabel(self):
        snarv = False

        with open("register.txt", 'r') as arq:
            for j in arq:
                self.remove_depois = QtWidgets.QLabel()
                self.remove_depois.setMaximumSize(QtCore.QSize(50,20))
                self.verticalLayout.addWidget(self.remove_depois)

                if("Arquivado" in j):
                    self.process = ProcessObj(j, 'y')
                else:
                    self.process = ProcessObj(j, 'n')

                self.verticalLayout.addWidget(self.process)



    ##Spawns a new process creation window
    def createProcess(self):
        self.newpwindow = QtWidgets.QMainWindow()
        self.ui = Ui_AddProcessWindow()
        self.ui.setupUi(self.newpwindow)
        self.newpwindow.show()



    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(500, 700)
        MainWindow.setMinimumSize(QtCore.QSize(500, 700))
        font = QtGui.QFont()
        font.setFamily("Segoe UI")
        font.setPointSize(10)
        MainWindow.setFont(font)
        MainWindow.setStyleSheet("color: rgb(200, 200, 200);\n"
"background-color: rgb(10, 10, 10);")
        **self.centralwidget = QtWidgets.QWidget(MainWindow)**
        **self.centralwidget.setObjectName("centralwidget")**
        **self.scroll = QtWidgets.QScrollArea()**
        **self.scroll.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)**
        **self.scroll.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)**
        **self.scroll.setWidgetResizable(True)**
        **self.scroll.setWidget(self.centralwidget)**
        self.scroll.setStyleSheet("QScrollBar {\n"
                                  "    background-color: rgb(43, 84, 126);\n"
                                  "}")
        self.verticalLayout = QtWidgets.QVBoxLayout()
        self.verticalLayout.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout.setSpacing(0)
        self.verticalLayout.setObjectName("verticalLayout")
        self.centralwidget.setLayout(self.verticalLayout)**


        ### TO BE FIXED THE NON-SHOWING BAR WHEN MANY PROCESSES ARE ADDED ###
        **self.top_bar = QtWidgets.QFrame(self.centralwidget)**
        **self.top_bar.setMaximumSize(QtCore.QSize(16777215, 50))**
        **self.top_bar.setStyleSheet("")**
        self.top_bar.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.top_bar.setFrameShadow(QtWidgets.QFrame.Raised)
        self.top_bar.setObjectName("top_bar")
        self.top_bar.setStyleSheet("background-color: rgb(43, 84, 126);\n")
        self.verticalLayout.addWidget(self.top_bar)**
        ### TO BE FIXED THE NON-SHOWING BAR WHEN MANY PROCESS ARE ADDED ###


        **self.refresh_button = QtWidgets.QPushButton(self.top_bar)**
        **self.refresh_button.move(300, 10)**
        **self.refresh_button.clicked.connect(self.refresh)**
        **self.refresh_button.clicked.connect(lambda: MainWindow.close())**

        **self.button_newP = QtWidgets.QPushButton(self.top_bar)**
        **self.button_newP.setMinimumSize(QtCore.QSize(100, 100))**
        **self.button_newP.setMaximumSize(QtCore.QSize(100, 100))**
        **self.button_newP.setIconSize(QtCore.QSize(100, 50))**
        self.button_newP.setStyleSheet("QPushButton {\n"
                                       "    background-position: center;    \n"
                                       "    background-color: rgb(60, 60, 60);\n"
                                       "}\n"
                                       "QPushButton:hover {\n"
                                       "    background-color: rgb(50, 50, 50);    \n"
                                       "    color: rgb(200, 200, 200);\n"
                                       "}\n"
                                       "QPushButton:pressed {\n"
                                       "    background-color: rgb(35, 35, 35);    \n"
                                       "    color: rgb(200, 200, 200);\n"
                                       "}")

        self.button_newP.clicked.connect(self.createProcess)




        ### PROCESS AREA ###
        
        self.addProcessLabel()

        ### PROCESS AREA ###



        self.content = QtWidgets.QFrame(self.centralwidget)
        self.content.setStyleSheet("")
        self.content.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.content.setFrameShadow(QtWidgets.QFrame.Raised)
        self.content.setObjectName("content")
        self.horizontalLayout = QtWidgets.QHBoxLayout(self.content)
        self.horizontalLayout.setObjectName("horizontalLayout")


 


        self.verticalLayout.addWidget(self.content)



        self.bottom = QtWidgets.QFrame(self.centralwidget)
        self.bottom.setMaximumSize(QtCore.QSize(16777215, 35))
        self.bottom.setStyleSheet("background-color: rgb(15, 15, 15)")
        self.bottom.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.bottom.setFrameShadow(QtWidgets.QFrame.Raised)
        self.bottom.setObjectName("bottom")
        self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.bottom)
        self.verticalLayout_2.setObjectName("verticalLayout_2")
        self.label_credits = QtWidgets.QLabel(self.bottom)
        font = QtGui.QFont()
        font.setFamily("Segoe UI")
        self.label_credits.setFont(font)
        self.label_credits.setStyleSheet("color: rgb(75, 75, 75);")
        self.label_credits.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
        self.label_credits.setObjectName("label_credits")
        self.verticalLayout_2.addWidget(self.label_credits)
        self.verticalLayout.addWidget(self.bottom)
        MainWindow.setCentralWidget(self.scroll)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 928, 21))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)


        #
        # FUNCTIONS
        #

        QtCore.QMetaObject.connectSlotsByName(MainWindow)

        self.retranslateUi(MainWindow)


    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "Processos"))
        self.label_credits.setText(_translate("MainWindow", "Created by: Gabriel"))
musicamante
  • 41,230
  • 6
  • 33
  • 58
  • 2 important suggestions: 1. Do not use symbols that alter syntax to indicate a specific point of the code, as it forces us to edit your code back in order to try it; a comment section is enough; 2. Files generated by the pyuic utility should *never* be manually modified, as doing it almost always results in problems (like yours); read the official guidelines about [using Designer](https://www.riverbankcomputing.com/static/Docs/PyQt5/designer.html). Your problem is that you created the frame as a child of `centralwidget`, which already has its own layout (the one containing the scroll area). – musicamante Nov 21 '21 at 19:31
  • Unfortunately, your code is very confusing (due to the fact that you tried to edit it, probably while attempting to merge two pyuic files), so it's very difficult to help you. I strongly suggest you to create a *new* UI in designer and set the base structure from there. If you then need to add other elements dynamically, use the widget that Designer automatically creates for the scroll area (normally called `scrollAreaWidgetContents`), set a layout for it and use that layout from your code (which will be your main script, and *must* be in a separate file, not the pyuic file). – musicamante Nov 21 '21 at 19:34
  • Does this answer your question? [QtDesigner changes will be lost after redesign User Interface](https://stackoverflow.com/questions/46544780/qtdesigner-changes-will-be-lost-after-redesign-user-interface) – musicamante Nov 21 '21 at 19:37

0 Answers0