Responsiveness, made in QT Designer, is not working. Python - python

I made an application design in QT Designer and saved it as a .ui file.
Next, converted .ui file into .py file with this command - pyuic5 -o design.py responsive_design.ui
After this, added this 👇
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
at the end of a file to make it work.
But, unfortunately, when my Python file starts, application opens with a static design, not responsive, as expected.
I see this -
Is it a QT bug or my mistake? Is it possible to resolve this problem?
My full code is below -
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'responsive_design.ui'
#
# Created by: PyQt5 UI code generator 5.15.0
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QApplication, QDialog, QMainWindow, QMessageBox
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 450)
MainWindow.setMinimumSize(QtCore.QSize(800, 450))
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(0, 0, 801, 451))
self.label.setText("")
self.label.setPixmap(QtGui.QPixmap("../Downloads/bg.png"))
self.label.setScaledContents(True)
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.label.setObjectName("label")
self.verticalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
self.verticalLayoutWidget.setGeometry(QtCore.QRect(-1, 0, 801, 451))
self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setObjectName("verticalLayout")
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.label_2 = QtWidgets.QLabel(self.verticalLayoutWidget)
self.label_2.setText("")
self.label_2.setPixmap(QtGui.QPixmap(""))
self.label_2.setScaledContents(False)
self.label_2.setAlignment(QtCore.Qt.AlignCenter)
self.label_2.setObjectName("label_2")
self.horizontalLayout.addWidget(self.label_2)
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem)
self.label_3 = QtWidgets.QLabel(self.verticalLayoutWidget)
self.label_3.setText("")
self.label_3.setPixmap(QtGui.QPixmap(""))
self.label_3.setScaledContents(False)
self.label_3.setAlignment(QtCore.Qt.AlignCenter)
self.label_3.setObjectName("label_3")
self.horizontalLayout.addWidget(self.label_3)
self.horizontalLayout.setStretch(0, 1)
self.horizontalLayout.setStretch(1, 4)
self.horizontalLayout.setStretch(2, 1)
self.verticalLayout.addLayout(self.horizontalLayout)
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.label_5 = QtWidgets.QLabel(self.verticalLayoutWidget)
self.label_5.setText("")
self.label_5.setObjectName("label_5")
self.horizontalLayout_2.addWidget(self.label_5)
self.label_6 = QtWidgets.QLabel(self.verticalLayoutWidget)
font = QtGui.QFont()
font.setFamily("Comic Sans MS")
font.setPointSize(16)
self.label_6.setFont(font)
self.label_6.setStyleSheet("background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(255, 255, 255, 236), stop:1 rgba(255, 255, 255, 220));\n"
"border-radius: 10px;")
self.label_6.setAlignment(QtCore.Qt.AlignCenter)
self.label_6.setObjectName("label_6")
self.horizontalLayout_2.addWidget(self.label_6)
self.label_4 = QtWidgets.QLabel(self.verticalLayoutWidget)
self.label_4.setText("")
self.label_4.setObjectName("label_4")
self.horizontalLayout_2.addWidget(self.label_4)
self.horizontalLayout_2.setStretch(0, 1)
self.horizontalLayout_2.setStretch(1, 5)
self.horizontalLayout_2.setStretch(2, 1)
self.verticalLayout.addLayout(self.horizontalLayout_2)
self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.label_7 = QtWidgets.QLabel(self.verticalLayoutWidget)
self.label_7.setText("")
self.label_7.setObjectName("label_7")
self.horizontalLayout_3.addWidget(self.label_7)
self.gridLayout = QtWidgets.QGridLayout()
self.gridLayout.setObjectName("gridLayout")
self.label_11 = QtWidgets.QLabel(self.verticalLayoutWidget)
font = QtGui.QFont()
font.setFamily("Comic Sans MS")
font.setPointSize(7)
self.label_11.setFont(font)
self.label_11.setAlignment(QtCore.Qt.AlignCenter)
self.label_11.setObjectName("label_11")
self.gridLayout.addWidget(self.label_11, 2, 0, 1, 1)
self.label_10 = QtWidgets.QLabel(self.verticalLayoutWidget)
self.label_10.setToolTip("")
self.label_10.setWhatsThis("")
self.label_10.setText("")
self.label_10.setPixmap(QtGui.QPixmap("../microphone.png"))
self.label_10.setAlignment(QtCore.Qt.AlignCenter)
self.label_10.setObjectName("label_10")
self.gridLayout.addWidget(self.label_10, 1, 0, 1, 1)
self.label_9 = QtWidgets.QLabel(self.verticalLayoutWidget)
self.label_9.setText("")
self.label_9.setAlignment(QtCore.Qt.AlignCenter)
self.label_9.setObjectName("label_9")
self.gridLayout.addWidget(self.label_9, 0, 0, 1, 1)
self.horizontalLayout_3.addLayout(self.gridLayout)
self.label_8 = QtWidgets.QLabel(self.verticalLayoutWidget)
self.label_8.setText("")
self.label_8.setObjectName("label_8")
self.horizontalLayout_3.addWidget(self.label_8)
self.horizontalLayout_3.setStretch(0, 5)
self.horizontalLayout_3.setStretch(1, 4)
self.horizontalLayout_3.setStretch(2, 5)
self.verticalLayout.addLayout(self.horizontalLayout_3)
self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.label_14 = QtWidgets.QLabel(self.verticalLayoutWidget)
self.label_14.setText("")
self.label_14.setObjectName("label_14")
self.horizontalLayout_4.addWidget(self.label_14)
self.gridLayout_2 = QtWidgets.QGridLayout()
self.gridLayout_2.setObjectName("gridLayout_2")
self.label_16 = QtWidgets.QLabel(self.verticalLayoutWidget)
self.label_16.setText("")
self.label_16.setObjectName("label_16")
self.gridLayout_2.addWidget(self.label_16, 2, 0, 1, 1)
self.label_15 = QtWidgets.QLabel(self.verticalLayoutWidget)
font = QtGui.QFont()
font.setFamily("Comic Sans MS")
font.setPointSize(12)
self.label_15.setFont(font)
self.label_15.setStyleSheet("background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(255, 255, 255, 236), stop:1 rgba(255, 255, 255, 220));\n"
"border-radius: 10px;")
self.label_15.setAlignment(QtCore.Qt.AlignCenter)
self.label_15.setObjectName("label_15")
self.gridLayout_2.addWidget(self.label_15, 1, 0, 1, 1)
self.label_13 = QtWidgets.QLabel(self.verticalLayoutWidget)
font = QtGui.QFont()
font.setFamily("Comic Sans MS")
font.setPointSize(7)
self.label_13.setFont(font)
self.label_13.setAlignment(QtCore.Qt.AlignCenter)
self.label_13.setObjectName("label_13")
self.gridLayout_2.addWidget(self.label_13, 0, 0, 1, 1)
self.gridLayout_2.setRowStretch(0, 1)
self.gridLayout_2.setRowStretch(1, 3)
self.horizontalLayout_4.addLayout(self.gridLayout_2)
self.label_12 = QtWidgets.QLabel(self.verticalLayoutWidget)
self.label_12.setText("")
self.label_12.setObjectName("label_12")
self.horizontalLayout_4.addWidget(self.label_12)
self.horizontalLayout_4.setStretch(0, 4)
self.horizontalLayout_4.setStretch(1, 5)
self.horizontalLayout_4.setStretch(2, 4)
self.verticalLayout.addLayout(self.horizontalLayout_4)
self.verticalLayout.setStretch(0, 2)
self.verticalLayout.setStretch(1, 8)
self.verticalLayout.setStretch(2, 2)
self.verticalLayout.setStretch(3, 6)
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.label_6.setText(_translate("MainWindow", "Output"))
self.label_11.setText(_translate("MainWindow", "I'm listening when microphone is visible"))
self.label_15.setText(_translate("MainWindow", "SAID"))
self.label_13.setText(_translate("MainWindow", "I Think You Said:"))
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())

first I installed the centrallayout, then I loaded all the elements to the layouts and I loaded these layouts to the centrallayout.
check the differences and edit it yourself
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'responsive_design.ui'
#
# Created by: PyQt5 UI code generator 5.15.0
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QApplication, QDialog, QMainWindow, QMessageBox, QVBoxLayout, QScrollArea, QWidget
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 450)
MainWindow.setMinimumSize(QtCore.QSize(800, 450))
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel()
self.label.setPixmap(QtGui.QPixmap("../Downloads/bg.png"))
self.label.setScaledContents(True)
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.label.setObjectName("label")
self.centralLayout = QVBoxLayout(self.centralwidget)
self.centralLayout.setContentsMargins(0,0,0,0)
self.centralLayout.addWidget(self.label)
self.verticalLayout = QtWidgets.QVBoxLayout(self.label)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setObjectName("verticalLayout")
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.label_2 = QtWidgets.QLabel()
self.label_2.setText("")
self.label_2.setPixmap(QtGui.QPixmap(""))
self.label_2.setScaledContents(False)
self.label_2.setAlignment(QtCore.Qt.AlignCenter)
self.label_2.setObjectName("label_2")
self.horizontalLayout.addWidget(self.label_2)
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem)
self.label_3 = QtWidgets.QLabel()
self.label_3.setText("")
self.label_3.setPixmap(QtGui.QPixmap(""))
self.label_3.setScaledContents(False)
self.label_3.setAlignment(QtCore.Qt.AlignCenter)
self.label_3.setObjectName("label_3")
self.horizontalLayout.addWidget(self.label_3)
self.horizontalLayout.setStretch(0, 1)
self.horizontalLayout.setStretch(1, 4)
self.horizontalLayout.setStretch(2, 1)
self.verticalLayout.addLayout(self.horizontalLayout)
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.label_5 = QtWidgets.QLabel()
self.label_5.setText("")
self.label_5.setObjectName("label_5")
self.horizontalLayout_2.addWidget(self.label_5)
self.label_6 = QtWidgets.QLabel()
font = QtGui.QFont()
font.setFamily("Comic Sans MS")
font.setPointSize(16)
self.label_6.setFont(font)
self.label_6.setStyleSheet("background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(255, 255, 255, 236), stop:1 rgba(255, 255, 255, 220));\n"
"border-radius: 10px;")
self.label_6.setAlignment(QtCore.Qt.AlignCenter)
self.label_6.setObjectName("label_6")
self.horizontalLayout_2.addWidget(self.label_6)
self.label_4 = QtWidgets.QLabel()
self.label_4.setText("")
self.label_4.setObjectName("label_4")
self.horizontalLayout_2.addWidget(self.label_4)
self.horizontalLayout_2.setStretch(0, 1)
self.horizontalLayout_2.setStretch(1, 5)
self.horizontalLayout_2.setStretch(2, 1)
self.verticalLayout.addLayout(self.horizontalLayout_2)
self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.label_7 = QtWidgets.QLabel()
self.label_7.setText("")
self.label_7.setObjectName("label_7")
self.horizontalLayout_3.addWidget(self.label_7)
self.gridLayout = QtWidgets.QGridLayout()
self.gridLayout.setObjectName("gridLayout")
self.label_11 = QtWidgets.QLabel()
font = QtGui.QFont()
font.setFamily("Comic Sans MS")
font.setPointSize(7)
self.label_11.setFont(font)
self.label_11.setAlignment(QtCore.Qt.AlignCenter)
self.label_11.setObjectName("label_11")
self.gridLayout.addWidget(self.label_11, 2, 0, 1, 1)
self.label_10 = QtWidgets.QLabel()
self.label_10.setToolTip("")
self.label_10.setWhatsThis("")
self.label_10.setText("")
self.label_10.setPixmap(QtGui.QPixmap("../microphone.png"))
self.label_10.setAlignment(QtCore.Qt.AlignCenter)
self.label_10.setObjectName("label_10")
self.gridLayout.addWidget(self.label_10, 1, 0, 1, 1)
self.label_9 = QtWidgets.QLabel()
self.label_9.setText("")
self.label_9.setAlignment(QtCore.Qt.AlignCenter)
self.label_9.setObjectName("label_9")
self.gridLayout.addWidget(self.label_9, 0, 0, 1, 1)
self.horizontalLayout_3.addLayout(self.gridLayout)
self.label_8 = QtWidgets.QLabel()
self.label_8.setText("")
self.label_8.setObjectName("label_8")
self.horizontalLayout_3.addWidget(self.label_8)
self.horizontalLayout_3.setStretch(0, 5)
self.horizontalLayout_3.setStretch(1, 4)
self.horizontalLayout_3.setStretch(2, 5)
self.verticalLayout.addLayout(self.horizontalLayout_3)
self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.label_14 = QtWidgets.QLabel()
self.label_14.setText("")
self.label_14.setObjectName("label_14")
self.horizontalLayout_4.addWidget(self.label_14)
self.gridLayout_2 = QtWidgets.QGridLayout()
self.gridLayout_2.setObjectName("gridLayout_2")
self.label_16 = QtWidgets.QLabel()
self.label_16.setText("")
self.label_16.setObjectName("label_16")
self.gridLayout_2.addWidget(self.label_16, 2, 0, 1, 1)
self.label_15 = QtWidgets.QLabel()
font = QtGui.QFont()
font.setFamily("Comic Sans MS")
font.setPointSize(12)
self.label_15.setFont(font)
self.label_15.setStyleSheet("background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(255, 255, 255, 236), stop:1 rgba(255, 255, 255, 220));\n"
"border-radius: 10px;")
self.label_15.setAlignment(QtCore.Qt.AlignCenter)
self.label_15.setObjectName("label_15")
self.gridLayout_2.addWidget(self.label_15, 1, 0, 1, 1)
self.label_13 = QtWidgets.QLabel()
font = QtGui.QFont()
font.setFamily("Comic Sans MS")
font.setPointSize(7)
self.label_13.setFont(font)
self.label_13.setAlignment(QtCore.Qt.AlignCenter)
self.label_13.setObjectName("label_13")
self.gridLayout_2.addWidget(self.label_13, 0, 0, 1, 1)
self.gridLayout_2.setRowStretch(0, 1)
self.gridLayout_2.setRowStretch(1, 3)
self.horizontalLayout_4.addLayout(self.gridLayout_2)
self.label_12 = QtWidgets.QLabel()
self.label_12.setText("")
self.label_12.setObjectName("label_12")
self.horizontalLayout_4.addWidget(self.label_12)
self.horizontalLayout_4.setStretch(0, 4)
self.horizontalLayout_4.setStretch(1, 5)
self.horizontalLayout_4.setStretch(2, 4)
self.verticalLayout.addLayout(self.horizontalLayout_4)
self.verticalLayout.setStretch(0, 2)
self.verticalLayout.setStretch(1, 8)
self.verticalLayout.setStretch(2, 2)
self.verticalLayout.setStretch(3, 6)
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.label_6.setText(_translate("MainWindow", "Output"))
self.label_11.setText(_translate("MainWindow", "I'm listening when microphone is visible"))
self.label_15.setText(_translate("MainWindow", "SAID"))
self.label_13.setText(_translate("MainWindow", "I Think You Said:"))
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())

Related

trying to make rock paper scissors game using random module,ifelse and pyqt5 and when i execute this program only first condition is executed

import random
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(640, 433)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
MainWindow.setSizePolicy(sizePolicy)
MainWindow.setMaximumSize(QtCore.QSize(641, 433))
MainWindow.setToolTipDuration(-1)
MainWindow.setStyleSheet("background-color: rgb(0, 0, 0);")
MainWindow.setAnimated(True)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.horizontalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
self.horizontalLayoutWidget.setGeometry(QtCore.QRect(0, 0, 160, 91))
self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget")
self.horizontalLayout = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget)
self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout.setObjectName("horizontalLayout")
self.label_4 = QtWidgets.QLabel(self.horizontalLayoutWidget)
self.label_4.setStyleSheet("background-color: rgb(255, 0, 0);\n"
"image: url(:/newPrefix/donkey kong.jfif);")
self.label_4.setText("")
self.label_4.setObjectName("label_4")
self.horizontalLayout.addWidget(self.label_4)
self.horizontalLayoutWidget_2 = QtWidgets.QWidget(self.centralwidget)
self.horizontalLayoutWidget_2.setGeometry(QtCore.QRect(160, 0, 400, 91))
self.horizontalLayoutWidget_2.setObjectName("horizontalLayoutWidget_2")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget_2)
self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.label_2 = QtWidgets.QLabel(self.horizontalLayoutWidget_2)
self.label_2.setStyleSheet("background-color: rgb(0, 0, 0);\n"
"font: 48pt \"MS Shell Dlg 2\";\n"
"color: rgb(255, 255, 255);")
self.label_2.setObjectName("label_2")
self.horizontalLayout_2.addWidget(self.label_2)
self.horizontalLayoutWidget_3 = QtWidgets.QWidget(self.centralwidget)
self.horizontalLayoutWidget_3.setGeometry(QtCore.QRect(320, 0, 160, 91))
self.horizontalLayoutWidget_3.setObjectName("horizontalLayoutWidget_3")
self.horizontalLayout_3 = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget_3)
self.horizontalLayout_3.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.label_3 = QtWidgets.QLabel(self.horizontalLayoutWidget_3)
self.label_3.setStyleSheet("background-color: rgb(0, 0, 0);\n"
"font: 48pt \"MS Shell Dlg 2\";\n"
"color: rgb(255, 255, 255);")
self.label_3.setObjectName("label_3")
self.horizontalLayout_3.addWidget(self.label_3)
self.horizontalLayoutWidget_4 = QtWidgets.QWidget(self.centralwidget)
self.horizontalLayoutWidget_4.setGeometry(QtCore.QRect(480, 0, 160, 91))
self.horizontalLayoutWidget_4.setObjectName("horizontalLayoutWidget_4")
self.horizontalLayout_4 = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget_4)
self.horizontalLayout_4.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.verticalLayout = QtWidgets.QVBoxLayout()
self.verticalLayout.setObjectName("verticalLayout")
self.label = QtWidgets.QLabel(self.horizontalLayoutWidget_4)
self.label.setStyleSheet("background-color: rgb(0, 85, 255);\n"
"image: url(:/newPrefix/OIP.jfif);")
self.label.setText("")
self.label.setObjectName("label")
self.verticalLayout.addWidget(self.label)
self.horizontalLayout_4.addLayout(self.verticalLayout)
self.horizontalLayoutWidget_5 = QtWidgets.QWidget(self.centralwidget)
self.horizontalLayoutWidget_5.setGeometry(QtCore.QRect(110, 90, 66, 31))
self.horizontalLayoutWidget_5.setObjectName("horizontalLayoutWidget_5")
self.horizontalLayout_5 = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget_5)
self.horizontalLayout_5.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_5.setObjectName("horizontalLayout_5")
self.lcdNumber = QtWidgets.QLCDNumber(self.horizontalLayoutWidget_5)
self.lcdNumber.setObjectName("lcdNumber")
self.horizontalLayout_5.addWidget(self.lcdNumber)
self.horizontalLayoutWidget_6 = QtWidgets.QWidget(self.centralwidget)
self.horizontalLayoutWidget_6.setGeometry(QtCore.QRect(420, 90, 66, 31))
self.horizontalLayoutWidget_6.setObjectName("horizontalLayoutWidget_6")
self.horizontalLayout_6 = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget_6)
self.horizontalLayout_6.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_6.setObjectName("horizontalLayout_6")
self.lcdNumber_2 = QtWidgets.QLCDNumber(self.horizontalLayoutWidget_6)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.lcdNumber_2.sizePolicy().hasHeightForWidth())
self.lcdNumber_2.setSizePolicy(sizePolicy)
self.lcdNumber_2.setToolTipDuration(-1)
self.lcdNumber_2.setLayoutDirection(QtCore.Qt.LeftToRight)
self.lcdNumber_2.setObjectName("lcdNumber_2")
self.horizontalLayout_6.addWidget(self.lcdNumber_2)
self.horizontalLayoutWidget_8 = QtWidgets.QWidget(self.centralwidget)
self.horizontalLayoutWidget_8.setGeometry(QtCore.QRect(190, 320, 245, 80))
self.horizontalLayoutWidget_8.setObjectName("horizontalLayoutWidget_8")
self.horizontalLayout_9 = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget_8)
self.horizontalLayout_9.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_9.setObjectName("horizontalLayout_9")
self.pushButton = QtWidgets.QPushButton(self.horizontalLayoutWidget_8)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton.sizePolicy().hasHeightForWidth())
self.pushButton.setSizePolicy(sizePolicy)
self.pushButton.setStyleSheet("background-color: rgb(255, 170, 0);")
self.pushButton.setText("")
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("rock.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.pushButton.setIcon(icon)
self.pushButton.setIconSize(QtCore.QSize(65, 47))
self.pushButton.setDefault(True)
self.pushButton.setFlat(False)
self.pushButton.setObjectName("pushButton")
self.horizontalLayout_9.addWidget(self.pushButton)
self.pushButton_2 = QtWidgets.QPushButton(self.horizontalLayoutWidget_8)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_2.sizePolicy().hasHeightForWidth())
self.pushButton_2.setSizePolicy(sizePolicy)
self.pushButton_2.setStyleSheet("background-color: rgb(255, 170, 0);")
self.pushButton_2.setText("")
icon1 = QtGui.QIcon()
icon1.addPixmap(QtGui.QPixmap("paper.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.pushButton_2.setIcon(icon1)
self.pushButton_2.setIconSize(QtCore.QSize(65, 47))
self.pushButton_2.setAutoDefault(True)
self.pushButton_2.setDefault(True)
self.pushButton_2.setFlat(False)
self.pushButton_2.setObjectName("pushButton_2")
self.horizontalLayout_9.addWidget(self.pushButton_2)
self.pushButton_3 = QtWidgets.QPushButton(self.horizontalLayoutWidget_8)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_3.sizePolicy().hasHeightForWidth())
self.pushButton_3.setSizePolicy(sizePolicy)
self.pushButton_3.setStyleSheet("background-color: rgb(255, 170, 0);")
self.pushButton_3.setText("")
icon2 = QtGui.QIcon()
icon2.addPixmap(QtGui.QPixmap("scissors.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.pushButton_3.setIcon(icon2)
self.pushButton_3.setIconSize(QtCore.QSize(65, 47))
self.pushButton_3.setObjectName("pushButton_3")
self.horizontalLayout_9.addWidget(self.pushButton_3)
self.label_7 = QtWidgets.QLabel(self.centralwidget)
self.label_7.setGeometry(QtCore.QRect(0, 140, 221, 169))
self.label_7.setStyleSheet("background-color: rgb(255, 170, 0);")
self.label_7.setText("")
self.label_7.setPixmap(QtGui.QPixmap("rps.png"))
self.label_7.setScaledContents(True)
self.label_7.setObjectName("label_7")
self.label_6 = QtWidgets.QLabel(self.centralwidget)
self.label_6.setGeometry(QtCore.QRect(418, 140, 221, 169))
self.label_6.setStyleSheet("background-color: rgb(255, 170, 0);")
self.label_6.setText("")
self.label_6.setPixmap(QtGui.QPixmap("rps.png"))
self.label_6.setScaledContents(True)
self.label_6.setObjectName("label_6")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 640, 21))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
self.pushButton.clicked.connect(self.showrocklabel_6)
self.pushButton_2.clicked.connect(self.showpaperlabel_6)
self.pushButton_3.clicked.connect(self.showscissorslabel_6)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.label_2.setText(_translate("MainWindow", " V"))
self.label_3.setText(_translate("MainWindow", " S"))
def random1(self):
C = random.randint(1, 3)
print(C)
L=[self.label_7.setPixmap(QtGui.QPixmap("rock.png")),self.label_7.setPixmap(QtGui.QPixmap("paper.png")),self.label_7.setPixmap(QtGui.QPixmap("scissors.png"))]
L[C]
"""if C == 1:
self.label_7.setPixmap(QtGui.QPixmap("rock.png"))
if C == 2:
self.label_7.setPixmap(QtGui.QPixmap("paper.png"))
ctrc += 1
if C == 3:
self.label_7.setPixmap(QtGui.QPixmap("scissors.png"))"""
def showrocklabel_6(self):
self.label_6.setPixmap(QtGui.QPixmap("rock.png"))
self.random1()
def showpaperlabel_6(self):
self.label_6.setPixmap(QtGui.QPixmap("paper.png"))
self.random1()
def showscissorslabel_6(self):
self.label_6.setPixmap(QtGui.QPixmap("scissors.png"))
self.random1()
import assets_rc
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())

Why my scrollbar is missing by using scrollArea on PyQT?

I want to put some articles on my scrollArea, so I build it on the QtDesigner, but when I executed my codes, I couldn't see my scrollbar. I've tried other solutions, but it didn't work.
I don't know what I miss, and I feel confused on how do I modify my code.
class Ui_NewsWidget(object):
def setupUi(self, NewsWidget):
NewsWidget.setObjectName("NewsWidget")
NewsWidget.resize(802, 600)
self.horizontalLayoutWidget_2 = QtWidgets.QWidget(NewsWidget)
self.horizontalLayoutWidget_2.setGeometry(QtCore.QRect(20, 100, 761, 481))
self.horizontalLayoutWidget_2.setObjectName("horizontalLayoutWidget_2")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget_2)
self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.news_listWidget = QtWidgets.QListWidget(self.horizontalLayoutWidget_2)
self.news_listWidget.setMaximumSize(QtCore.QSize(250, 16777215))
self.news_listWidget.setObjectName("news_listWidget")
self.horizontalLayout_2.addWidget(self.news_listWidget)
self.scrollArea = QtWidgets.QScrollArea(self.horizontalLayoutWidget_2)
self.scrollArea.setWidgetResizable(False)
self.scrollArea.setObjectName("scrollArea")
self.scrollAreaWidgetContents = QtWidgets.QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 501, 477))
self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
self.verticalLayoutWidget = QtWidgets.QWidget(self.scrollAreaWidgetContents)
self.verticalLayoutWidget.setGeometry(QtCore.QRect(0, 0, 501, 481))
self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setObjectName("verticalLayout")
self.news_txtheading = QtWidgets.QLabel(self.verticalLayoutWidget)
self.news_txtheading.setMaximumSize(QtCore.QSize(16777215, 40))
font = QtGui.QFont()
font.setPointSize(14)
self.news_txtheading.setFont(font)
self.news_txtheading.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignVCenter)
self.news_txtheading.setObjectName("news_txtheading")
self.verticalLayout.addWidget(self.news_txtheading)
self.news_txtcontent = QtWidgets.QLabel(self.verticalLayoutWidget)
font = QtGui.QFont()
font.setPointSize(12)
self.news_txtcontent.setFont(font)
self.news_txtcontent.setWordWrap(True)
self.news_txtcontent.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop)
self.news_txtcontent.setObjectName("news_txtcontent")
self.verticalLayout.addWidget(self.news_txtcontent)
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.horizontalLayout_2.addWidget(self.scrollArea)
self.retranslateUi(NewsWidget)
QtCore.QMetaObject.connectSlotsByName(NewsWidget)

How to add media player in my QmainWindow widget?

THIS IS THE MAIN UI:
I want to add a media player in this black bordered box. I have no idea how to I integrate predesigned QMediaplayers into my window. This black box is a widget that I have set to promoted to QvideoWidget in order to use it but I have little to no idea how to use it.
MY MAIN WINDOW
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'mainscreen.ui'
#
# Created by: PyQt5 UI code generator 5.15.2
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(862, 580)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setSpacing(0)
self.verticalLayout.setObjectName("verticalLayout")
self.Header = QtWidgets.QFrame(self.centralwidget)
self.Header.setMaximumSize(QtCore.QSize(16777215, 50))
self.Header.setStyleSheet("background-color: rgb(239, 128, 0);")
self.Header.setFrameShape(QtWidgets.QFrame.WinPanel)
self.Header.setFrameShadow(QtWidgets.QFrame.Raised)
self.Header.setObjectName("Header")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.Header)
self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_2.setSpacing(0)
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.Title_bar_container = QtWidgets.QFrame(self.Header)
self.Title_bar_container.setStyleSheet("background-color: rgb(239, 133, 0);")
self.Title_bar_container.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.Title_bar_container.setFrameShadow(QtWidgets.QFrame.Raised)
self.Title_bar_container.setObjectName("Title_bar_container")
self.Slider = QtWidgets.QFrame(self.Title_bar_container)
self.Slider.setGeometry(QtCore.QRect(0, 0, 71, 52))
self.Slider.setStyleSheet("background-color: rgb(239, 133, 0);")
self.Slider.setFrameShape(QtWidgets.QFrame.NoFrame)
self.Slider.setFrameShadow(QtWidgets.QFrame.Raised)
self.Slider.setObjectName("Slider")
self.horizontalLayout_4 = QtWidgets.QHBoxLayout(self.Slider)
self.horizontalLayout_4.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_4.setSpacing(0)
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.pushButton_4 = QtWidgets.QPushButton(self.Slider)
self.pushButton_4.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.pushButton_4.setStyleSheet("\n"
"QPushButton{\n"
"background-color: rgb(239, 133, 0);\n"
"border:none;\n"
"}\n"
"\n"
"QPushButton::hover{\n"
" \n"
" background-color: rgb(243, 164, 50);\n"
"}")
self.pushButton_4.setText("")
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(":/icon_pics/png/004-list.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.pushButton_4.setIcon(icon)
self.pushButton_4.setIconSize(QtCore.QSize(24, 24))
self.pushButton_4.setObjectName("pushButton_4")
self.horizontalLayout_4.addWidget(self.pushButton_4)
self.horizontalLayout_2.addWidget(self.Title_bar_container)
self.Top_right_buttons = QtWidgets.QFrame(self.Header)
self.Top_right_buttons.setMaximumSize(QtCore.QSize(100, 16777215))
self.Top_right_buttons.setStyleSheet("background-color: rgb(239, 133, 0);")
self.Top_right_buttons.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.Top_right_buttons.setFrameShadow(QtWidgets.QFrame.Raised)
self.Top_right_buttons.setObjectName("Top_right_buttons")
self.horizontalLayout_3 = QtWidgets.QHBoxLayout(self.Top_right_buttons)
self.horizontalLayout_3.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_3.setSpacing(0)
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.pushButton = QtWidgets.QPushButton(self.Top_right_buttons)
self.pushButton.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.pushButton.setMouseTracking(False)
self.pushButton.setWhatsThis("")
self.pushButton.setStyleSheet("\n"
"QPushButton{\n"
"background-color: rgb(239, 133, 0);\n"
"border:none;\n"
"}\n"
"\n"
"QPushButton::hover{\n"
" \n"
" background-color: rgb(243, 164, 50);\n"
"}")
self.pushButton.setText("")
icon1 = QtGui.QIcon()
icon1.addPixmap(QtGui.QPixmap(":/icon_pics/png/001-minimize.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.pushButton.setIcon(icon1)
self.pushButton.setIconSize(QtCore.QSize(24, 24))
self.pushButton.setFlat(False)
self.pushButton.setObjectName("pushButton")
self.horizontalLayout_3.addWidget(self.pushButton)
self.pushButton_2 = QtWidgets.QPushButton(self.Top_right_buttons)
self.pushButton_2.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.pushButton_2.setStyleSheet("background-color: rgb(239, 133, 0);\n"
"border:none;\n"
"\n"
"QPushButton::hover{\n"
" \n"
" background-color: rgb(243, 164, 50);\n"
"}")
self.pushButton_2.setText("")
icon2 = QtGui.QIcon()
icon2.addPixmap(QtGui.QPixmap(":/icon_pics/png/003-expand.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.pushButton_2.setIcon(icon2)
self.pushButton_2.setIconSize(QtCore.QSize(24, 24))
self.pushButton_2.setObjectName("pushButton_2")
self.horizontalLayout_3.addWidget(self.pushButton_2)
self.pushButton_3 = QtWidgets.QPushButton(self.Top_right_buttons)
self.pushButton_3.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.pushButton_3.setStyleSheet("\n"
"QPushButton{\n"
"background-color: rgb(239, 133, 0);\n"
"border:none;\n"
"}\n"
"\n"
"QPushButton::hover{\n"
" \n"
" background-color: rgb(243, 164, 50);\n"
"}")
self.pushButton_3.setText("")
icon3 = QtGui.QIcon()
icon3.addPixmap(QtGui.QPixmap(":/icon_pics/png/002-remove.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.pushButton_3.setIcon(icon3)
self.pushButton_3.setIconSize(QtCore.QSize(24, 24))
self.pushButton_3.setObjectName("pushButton_3")
self.horizontalLayout_3.addWidget(self.pushButton_3)
self.horizontalLayout_2.addWidget(self.Top_right_buttons)
self.verticalLayout.addWidget(self.Header)
self.Main_body = QtWidgets.QFrame(self.centralwidget)
self.Main_body.setStyleSheet("background-color: rgb(0, 0, 127);")
self.Main_body.setFrameShape(QtWidgets.QFrame.NoFrame)
self.Main_body.setFrameShadow(QtWidgets.QFrame.Raised)
self.Main_body.setObjectName("Main_body")
self.horizontalLayout = QtWidgets.QHBoxLayout(self.Main_body)
self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout.setSpacing(0)
self.horizontalLayout.setObjectName("horizontalLayout")
self.Left_side_menu = QtWidgets.QFrame(self.Main_body)
self.Left_side_menu.setMaximumSize(QtCore.QSize(70, 16777215))
self.Left_side_menu.setStyleSheet("background-color: rgb(239, 128, 0);\n"
"background-color: rgb(243, 164, 50);")
self.Left_side_menu.setFrameShape(QtWidgets.QFrame.NoFrame)
self.Left_side_menu.setFrameShadow(QtWidgets.QFrame.Raised)
self.Left_side_menu.setObjectName("Left_side_menu")
self.horizontalLayout.addWidget(self.Left_side_menu)
self.Main_screen = QtWidgets.QFrame(self.Main_body)
self.Main_screen.setStyleSheet("background-color: rgb(239, 128, 0);\n"
"background-color: rgb(243, 164, 50);")
self.Main_screen.setFrameShape(QtWidgets.QFrame.NoFrame)
self.Main_screen.setFrameShadow(QtWidgets.QFrame.Raised)
self.Main_screen.setObjectName("Main_screen")
self.widget = QVideoWidget(self.Main_screen)
self.widget.setGeometry(QtCore.QRect(70, 50, 201, 161))
self.widget.setObjectName("widget")
self.horizontalLayout.addWidget(self.Main_screen)
self.Right_side_menu = QtWidgets.QFrame(self.Main_body)
self.Right_side_menu.setMaximumSize(QtCore.QSize(70, 16777215))
self.Right_side_menu.setStyleSheet("background-color: rgb(239, 128, 0);\n"
"background-color: rgb(243, 164, 50);")
self.Right_side_menu.setFrameShape(QtWidgets.QFrame.NoFrame)
self.Right_side_menu.setFrameShadow(QtWidgets.QFrame.Raised)
self.Right_side_menu.setObjectName("Right_side_menu")
self.horizontalLayout.addWidget(self.Right_side_menu)
self.verticalLayout.addWidget(self.Main_body)
self.Footer = QtWidgets.QFrame(self.centralwidget)
self.Footer.setMaximumSize(QtCore.QSize(16777215, 50))
self.Footer.setStyleSheet("background-color: rgb(239, 128, 0);\n"
"background-color: rgb(243, 164, 50);")
self.Footer.setFrameShape(QtWidgets.QFrame.NoFrame)
self.Footer.setFrameShadow(QtWidgets.QFrame.Raised)
self.Footer.setObjectName("Footer")
self.verticalLayout.addWidget(self.Footer)
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
from PyQt5.QtMultimediaWidgets import QVideoWidget
import Icons_rc
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
You have to create a new file where you create a class that inherits from the appropriate widget and use Ui_MainWindow to fill it, there you must create the QMediaPlayer to set it in the QVideoWidget.
Assuming the file provided by the OP is gui.py then the solution is:
import sys
from PyQt5 import QtCore, QtWidgets, QtMultimedia
from gui import Ui_MainWindow
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.player = QtMultimedia.QMediaPlayer(
self, QtMultimedia.QMediaPlayer.VideoSurface
)
url = QtCore.QUrl(
"https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_1920_18MG.mp4"
)
self.player.setMedia(QtMultimedia.QMediaContent(url))
self.player.setVideoOutput(self.ui.widget)
self.player.play()
def main(args):
app = QtWidgets.QApplication(args)
widget = MainWindow()
widget.show()
ret = app.exec_()
sys.exit(ret)
if __name__ == "__main__":
main(sys.argv)

Not able to Configure Scroll Area in Pyqt5 Python

Complete Code
I am expecting a scroll bar should get auto populate so that user can see the rest of the item.
in that highlighted area I tried
created one widget
added one Scroll Area under that widget
add a from lay out under Scroll Area
adding items to that from layout.
but the scroll area is not working.
#!/usr/bin/python
# -*- coding: utf-8 -*-
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName('MainWindow')
MainWindow.resize(817, 588)
sizePolicy = \
QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred,
QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
MainWindow.setSizePolicy(sizePolicy)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName('centralwidget')
self.verticalLayoutWidget = \
QtWidgets.QWidget(self.centralwidget)
self.verticalLayoutWidget.setGeometry(QtCore.QRect(20, 40, 761,
60))
self.verticalLayoutWidget.setObjectName('verticalLayoutWidget')
self.verticalLayout = \
QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setObjectName('verticalLayout')
self.gridLayout = QtWidgets.QGridLayout()
self.gridLayout.setSizeConstraint(QtWidgets.QLayout.SetDefaultConstraint)
self.gridLayout.setObjectName('gridLayout')
self.label = QtWidgets.QLabel(self.verticalLayoutWidget)
self.label.setObjectName('label')
self.gridLayout.addWidget(
self.label,
0,
0,
1,
1,
QtCore.Qt.AlignLeft,
)
self.searchString = \
QtWidgets.QLineEdit(self.verticalLayoutWidget)
self.searchString.setMaximumSize(QtCore.QSize(673, 16777215))
self.searchString.setObjectName('searchString')
self.gridLayout.addWidget(self.searchString, 0, 1, 1, 1)
self.submit = QtWidgets.QPushButton(self.verticalLayoutWidget)
self.submit.setObjectName('submit')
self.gridLayout.addWidget(self.submit, 0, 2, 1, 1)
self.verticalLayout.addLayout(self.gridLayout)
self.errorLabel = QtWidgets.QLabel(self.centralwidget)
self.errorLabel.setGeometry(QtCore.QRect(30, 10, 751, 16))
self.errorLabel.setText('')
self.errorLabel.setObjectName('errorLabel')
self.groupBox = QtWidgets.QGroupBox(self.centralwidget)
self.groupBox.setGeometry(QtCore.QRect(40, 140, 361, 151))
self.groupBox.setObjectName('groupBox')
self.serverList = QtWidgets.QListWidget(self.groupBox)
self.serverList.setEnabled(True)
self.serverList.setGeometry(QtCore.QRect(10, 20, 331, 121))
self.serverList.setSelectionMode(QtWidgets.QAbstractItemView.MultiSelection)
self.serverList.setResizeMode(QtWidgets.QListView.Fixed)
self.serverList.setObjectName('serverList')
item = QtWidgets.QListWidgetItem()
self.serverList.addItem(item)
item = QtWidgets.QListWidgetItem()
self.serverList.addItem(item)
item = QtWidgets.QListWidgetItem()
self.serverList.addItem(item)
self.groupBox_2 = QtWidgets.QGroupBox(self.centralwidget)
self.groupBox_2.setGeometry(QtCore.QRect(410, 140, 361, 151))
self.groupBox_2.setObjectName('groupBox_2')
self.autoDownload = QtWidgets.QCheckBox(self.groupBox_2)
self.autoDownload.setGeometry(QtCore.QRect(10, 30, 121, 20))
self.autoDownload.setObjectName('autoDownload')
self.specificFileFlag = QtWidgets.QCheckBox(self.groupBox_2)
self.specificFileFlag.setGeometry(QtCore.QRect(10, 60, 171, 20))
self.specificFileFlag.setObjectName('specificFileFlag')
self.downloadSelected = QtWidgets.QPushButton(self.groupBox_2)
self.downloadSelected.setGeometry(QtCore.QRect(10, 97, 141, 31))
self.downloadSelected.setObjectName('downloadSelected')
self.searchArchive = QtWidgets.QCheckBox(self.groupBox_2)
self.searchArchive.setGeometry(QtCore.QRect(170, 30, 141, 20))
self.searchArchive.setObjectName('searchArchive')
self.checkBox = QtWidgets.QCheckBox(self.groupBox_2)
self.checkBox.setGeometry(QtCore.QRect(170, 60, 191, 21))
self.checkBox.setObjectName('checkBox')
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(640, 540, 161, 20))
self.label_2.setObjectName('label_2')
self.selectedServer = QtWidgets.QLabel(self.centralwidget)
self.selectedServer.setGeometry(QtCore.QRect(30, 120, 751, 21))
self.selectedServer.setText('')
self.selectedServer.setObjectName('selectedServer')
self.widget = QtWidgets.QWidget(self.centralwidget)
self.widget.setGeometry(QtCore.QRect(30, 300, 761, 241))
self.widget.setObjectName('widget')
self.scrollArea = QtWidgets.QScrollArea(self.widget)
self.scrollArea.setGeometry(QtCore.QRect(9, 6, 731, 221))
self.scrollArea.setObjectName('scrollArea')
self.scrollAreaWidgetContents = QtWidgets.QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0,
729, 219))
self.scrollAreaWidgetContents.setObjectName('scrollAreaWidgetContents'
)
self.formLayoutWidget = \
QtWidgets.QWidget(self.scrollAreaWidgetContents)
self.formLayoutWidget.setGeometry(QtCore.QRect(0, 1, 731, 221))
self.formLayoutWidget.setObjectName('formLayoutWidget')
self.formLayout = QtWidgets.QFormLayout(self.formLayoutWidget)
self.formLayout.setContentsMargins(9, 9, 9, 9)
self.formLayout.setObjectName('formLayout')
self.checkBox_2 = QtWidgets.QCheckBox(self.formLayoutWidget)
self.checkBox_2.setObjectName('checkBox_2')
self.formLayout.setWidget(0, QtWidgets.QFormLayout.LabelRole,
self.checkBox_2)
self.progressBar = QtWidgets.QProgressBar(self.formLayoutWidget)
self.progressBar.setProperty('value', 24)
self.progressBar.setObjectName('progressBar')
self.formLayout.setWidget(0, QtWidgets.QFormLayout.FieldRole,
self.progressBar)
self.checkBox_3 = QtWidgets.QCheckBox(self.formLayoutWidget)
self.checkBox_3.setObjectName('checkBox_3')
self.formLayout.setWidget(1, QtWidgets.QFormLayout.LabelRole,
self.checkBox_3)
self.progressBar_2 = \
QtWidgets.QProgressBar(self.formLayoutWidget)
self.progressBar_2.setProperty('value', 24)
self.progressBar_2.setObjectName('progressBar_2')
self.formLayout.setWidget(1, QtWidgets.QFormLayout.FieldRole,
self.progressBar_2)
self.checkBox_4 = QtWidgets.QCheckBox(self.formLayoutWidget)
self.checkBox_4.setObjectName('checkBox_4')
self.formLayout.setWidget(2, QtWidgets.QFormLayout.LabelRole,
self.checkBox_4)
self.progressBar_3 = \
QtWidgets.QProgressBar(self.formLayoutWidget)
self.progressBar_3.setProperty('value', 24)
self.progressBar_3.setObjectName('progressBar_3')
self.formLayout.setWidget(2, QtWidgets.QFormLayout.FieldRole,
self.progressBar_3)
self.checkBox_5 = QtWidgets.QCheckBox(self.formLayoutWidget)
self.checkBox_5.setObjectName('checkBox_5')
self.formLayout.setWidget(3, QtWidgets.QFormLayout.LabelRole,
self.checkBox_5)
self.progressBar_4 = \
QtWidgets.QProgressBar(self.formLayoutWidget)
self.progressBar_4.setProperty('value', 24)
self.progressBar_4.setObjectName('progressBar_4')
self.formLayout.setWidget(3, QtWidgets.QFormLayout.FieldRole,
self.progressBar_4)
count = 6
c = 0
checkBox = []
while count < 10:
checkBox.append(QtWidgets.QCheckBox(self.formLayoutWidget))
checkBox[c].setObjectName('checkBox_' + str(c))
checkBox[c].setText('test_' + str(c))
self.formLayout.setWidget(count,
QtWidgets.QFormLayout.LabelRole, checkBox[c])
self.formLayout.setWidget(count,
QtWidgets.QFormLayout.FieldRole,
QtWidgets.QProgressBar(self.formLayoutWidget))
count = count + 1
c = c + 1
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName('statusbar')
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate('MainWindow', 'MainWindow'
))
self.label.setText(_translate('MainWindow',
'<html><head/><body><p><span style=" font-weight:600; color:#000000;">Search String</span><span style=" font-weight:600; color:#ff0000;">*</span></p></body></html>'
))
self.submit.setText(_translate('MainWindow', 'Search'))
self.groupBox.setTitle(_translate('MainWindow', 'Server List'))
__sortingEnabled = self.serverList.isSortingEnabled()
self.serverList.setSortingEnabled(False)
item = self.serverList.item(0)
item.setText(_translate('MainWindow', 'TVOL'))
item = self.serverList.item(1)
item.setText(_translate('MainWindow', 'QA2'))
item = self.serverList.item(2)
item.setText(_translate('MainWindow', 'CVOL'))
self.serverList.setSortingEnabled(__sortingEnabled)
self.groupBox_2.setTitle(_translate('MainWindow',
'Other Configuration'))
self.autoDownload.setToolTip(_translate('MainWindow',
'<html><head/><body><p><br/></p></body></html>'))
self.autoDownload.setText(_translate('MainWindow',
'Auto Download'))
self.specificFileFlag.setToolTip(_translate('MainWindow',
'<html><head/><body><p>write the file name in "Search String" and Click on Search Button</p></body></html>'
))
self.specificFileFlag.setText(_translate('MainWindow',
'Download Specific file'))
self.downloadSelected.setText(_translate('MainWindow',
'Download Selected'))
self.searchArchive.setText(_translate('MainWindow',
'Search in Archive'))
self.checkBox.setToolTip(_translate('MainWindow',
'<html><head/><body><p>This option will try to compress the file in server before downloading</p></body></html>'
))
self.checkBox.setText(_translate('MainWindow',
'Compress Before Download'))
self.label_2.setText(_translate('MainWindow',
'<html><head/><body><p><span style=" color:#969696;">Created by - Sudipto Khan</span></p></body></html>'
))
self.checkBox_2.setText(_translate('MainWindow', 'CheckBox'))
self.checkBox_3.setText(_translate('MainWindow', 'CheckBox'))
self.checkBox_4.setText(_translate('MainWindow', 'CheckBox'))
self.checkBox_5.setText(_translate('MainWindow', 'CheckBox'))
if __name__ == '__main__':
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())

Widgets not displaying in Scroll Area

I created two .ui files using pyqt designer: one being a Main Window and another being a Widget. Whenever I try to add a widget to the scroll area in my Main Window, it doesn't display on the screen and i can't figure out why.
Sorry if it's a stupid question, i'm still learning pyqt5 and pyqt designer. Any help would be appreciated, Thank you.
CODE:
class Window(QMainWindow):
def __init__(self):
super(Window,self).__init__()
self.ui=Ui_Reddit()
self.ui.setupUi(self)
self.setStyle(QStyleFactory.create('Cleanlooks'))
#self.setGeometry(300, 300, 600, 600)
self.setWindowTitle("Reddit")
self.show()
self.mainWindow()
def mainWindow(self):
#to handle all the api calls using praw
self.x = RedditApi()
self.printSubmissions()
def printSubmissions(self):
#Gets the list of all submission titles to be displayed
#TO DO: Get and add other things like points and comments
self.submissions = self.x.showSubmissions()
for submission in self.submissions:
card = QWidget()
card_ui = Ui_Card()
card_ui.setupUi(card)
card_ui.title.setText(submission)
self.ui.verticalLayout_2.addWidget(card)
Ui_Reddit:
class Ui_Reddit(object):
def setupUi(self, Reddit):
Reddit.setObjectName("Reddit")
Reddit.resize(800, 600)
Reddit.setTabShape(QtWidgets.QTabWidget.Rounded)
self.centralwidget = QtWidgets.QWidget(Reddit)
self.centralwidget.setObjectName("centralwidget")
self.scrollArea = QtWidgets.QScrollArea(self.centralwidget)
self.scrollArea.setGeometry(QtCore.QRect(10, 60, 781, 531))
self.scrollArea.setWidgetResizable(True)
self.scrollArea.setObjectName("scrollArea")
self.scrollAreaWidgetContents = QtWidgets.QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 779,
529))
self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
self.verticalLayoutWidget_2 =
QtWidgets.QWidget(self.scrollAreaWidgetContents)
self.verticalLayoutWidget_2.setGeometry(QtCore.QRect(-1, -1, 811,
551))
self.verticalLayoutWidget_2.setObjectName("verticalLayoutWidget_2")
self.verticalLayout_2 =
QtWidgets.QVBoxLayout(self.verticalLayoutWidget_2)
self.verticalLayout_2.setContentsMargins(0, 0, 0, 0)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.horizontalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
self.horizontalLayoutWidget.setGeometry(QtCore.QRect(0, 0, 801, 51))
self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget")
self.horizontalLayout =
QtWidgets.QHBoxLayout(self.horizontalLayoutWidget)
self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout.setObjectName("horizontalLayout")
self.label = QtWidgets.QLabel(self.horizontalLayoutWidget)
self.label.setIndent(5)
self.label.setObjectName("label")
self.horizontalLayout.addWidget(self.label)
self.comboBox = QtWidgets.QComboBox(self.horizontalLayoutWidget)
self.comboBox.setObjectName("comboBox")
self.horizontalLayout.addWidget(self.comboBox)
spacerItem = QtWidgets.QSpacerItem(40, 20,
QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem)
self.search_bar = QtWidgets.QLineEdit(self.horizontalLayoutWidget)
self.search_bar.setText("")
self.search_bar.setObjectName("search_bar")
self.horizontalLayout.addWidget(self.search_bar)
self.pushButton = QtWidgets.QPushButton(self.horizontalLayoutWidget)
self.pushButton.setFlat(False)
self.pushButton.setObjectName("pushButton")
self.horizontalLayout.addWidget(self.pushButton)
spacerItem1 = QtWidgets.QSpacerItem(40, 20,
QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem1)
Reddit.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(Reddit)
self.statusbar.setObjectName("statusbar")
Reddit.setStatusBar(self.statusbar)
self.retranslateUi(Reddit)
QtCore.QMetaObject.connectSlotsByName(Reddit)
def retranslateUi(self, Reddit):
_translate = QtCore.QCoreApplication.translate
Reddit.setWindowTitle(_translate("Reddit", "MainWindow"))
self.label.setText(_translate("Reddit", "TextLabel"))
self.search_bar.setPlaceholderText(_translate("Reddit", "Search"))
self.pushButton.setText(_translate("Reddit", "PushButton"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Reddit = QtWidgets.QMainWindow()
ui = Ui_Reddit()
ui.setupUi(Reddit)
Reddit.show()
sys.exit(app.exec_())
Ui_Card:
class Ui_Card(object):
def setupUi(self, Card):
Card.setObjectName("Card")
Card.setWindowModality(QtCore.Qt.NonModal)
Card.setEnabled(True)
Card.resize(771, 134)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred,
QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(1)
sizePolicy.setHeightForWidth(Card.sizePolicy().hasHeightForWidth())
Card.setSizePolicy(sizePolicy)
self.title = QtWidgets.QLabel(Card)
self.title.setGeometry(QtCore.QRect(6, 10, 761, 21))
font = QtGui.QFont()
font.setPointSize(12)
self.title.setFont(font)
self.title.setObjectName("title")
self.user = QtWidgets.QLabel(Card)
self.user.setGeometry(QtCore.QRect(20, 40, 47, 13))
font = QtGui.QFont()
font.setPointSize(7)
self.user.setFont(font)
self.user.setObjectName("user")
self.label_3 = QtWidgets.QLabel(Card)
self.label_3.setGeometry(QtCore.QRect(70, 30, 20, 31))
font = QtGui.QFont()
font.setPointSize(16)
self.label_3.setFont(font)
self.label_3.setObjectName("label_3")
self.subreddit = QtWidgets.QLabel(Card)
self.subreddit.setGeometry(QtCore.QRect(90, 40, 47, 13))
font = QtGui.QFont()
font.setPointSize(7)
self.subreddit.setFont(font)
self.subreddit.setObjectName("subreddit")
self.horizontalLayoutWidget = QtWidgets.QWidget(Card)
self.horizontalLayoutWidget.setGeometry(QtCore.QRect(10, 60, 771,
31))
self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget")
self.horizontalLayout =
QtWidgets.QHBoxLayout(self.horizontalLayoutWidget)
self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout.setObjectName("horizontalLayout")
spacerItem = QtWidgets.QSpacerItem(40, 20,
QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem)
self.comments = QtWidgets.QLabel(self.horizontalLayoutWidget)
self.comments.setObjectName("comments")
self.horizontalLayout.addWidget(self.comments)
self.upvote = QtWidgets.QPushButton(self.horizontalLayoutWidget)
self.upvote.setText("")
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("upvoteArrow.jpg"), QtGui.QIcon.Normal,
QtGui.QIcon.Off)
self.upvote.setIcon(icon)
self.upvote.setFlat(True)
self.upvote.setObjectName("upvote")
self.horizontalLayout.addWidget(self.upvote)
self.downvote = QtWidgets.QPushButton(self.horizontalLayoutWidget)
self.downvote.setFlat(True)
self.downvote.setObjectName("downvote")
self.horizontalLayout.addWidget(self.downvote)
spacerItem1 = QtWidgets.QSpacerItem(40, 20,
QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem1)
self.line = QtWidgets.QFrame(Card)
self.line.setGeometry(QtCore.QRect(0, 100, 771, 21))
self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line.setLineWidth(3)
self.line.setFrameShape(QtWidgets.QFrame.HLine)
self.line.setObjectName("line")
self.retranslateUi(Card)
QtCore.QMetaObject.connectSlotsByName(Card)
def retranslateUi(self, Card):
_translate = QtCore.QCoreApplication.translate
Card.setWindowTitle(_translate("Card", "Form"))
self.title.setText(_translate("Card", "TextLabel"))
self.user.setText(_translate("Card", "TextLabel"))
self.label_3.setText(_translate("Card", "-"))
self.subreddit.setText(_translate("Card", "TextLabel"))
self.comments.setText(_translate("Card", "TextLabel"))
self.downvote.setText(_translate("Card", "downvote"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Card = QtWidgets.QWidget()
ui = Ui_Card()
ui.setupUi(Card)
Card.show()
sys.exit(app.exec_())

Categories