Related
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_())
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_())
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_())
I am trying to update my QLCDNumber, but I failed several times. In my code, you can see that I want to take the input numbers from the double spin boxes and show them as a total sum of the previous land use values in my LCD widget. I have created a function with .value() but it doesn't work properly. The code is bit large, but I highlighted the QLCDNumber part.
Screenshot here:
values to take as inputs
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1039, 654)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.tabWidget = QtWidgets.QTabWidget(self.centralwidget)
self.tabWidget.setGeometry(QtCore.QRect(10, 0, 1001, 621))
self.tabWidget.setObjectName("tabWidget")
self.tab = QtWidgets.QWidget()
self.tab.setObjectName("tab")
self.groupBox = QtWidgets.QGroupBox(self.tab)
self.groupBox.setGeometry(QtCore.QRect(10, 40, 241, 521))
font = QtGui.QFont()
font.setPointSize(11)
self.groupBox.setFont(font)
self.groupBox.setTitle("")
self.groupBox.setObjectName("groupBox")
self.layoutWidget_5 = QtWidgets.QWidget(self.groupBox)
self.layoutWidget_5.setGeometry(QtCore.QRect(0, 50, 234, 26))
self.layoutWidget_5.setObjectName("layoutWidget_5")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.layoutWidget_5)
self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.grass_label = QtWidgets.QLabel(self.layoutWidget_5)
font = QtGui.QFont()
font.setPointSize(12)
self.grass_label.setFont(font)
self.grass_label.setObjectName("grass_label")
self.horizontalLayout_2.addWidget(self.grass_label)
self.grass_value = QtWidgets.QDoubleSpinBox(self.layoutWidget_5)
self.grass_value.setSingleStep(0.05)
self.grass_value.setObjectName("grass_value")
self.horizontalLayout_2.addWidget(self.grass_value)
self.layoutWidget_6 = QtWidgets.QWidget(self.groupBox)
self.layoutWidget_6.setGeometry(QtCore.QRect(0, 80, 234, 26))
self.layoutWidget_6.setObjectName("layoutWidget_6")
self.horizontalLayout_3 = QtWidgets.QHBoxLayout(self.layoutWidget_6)
self.horizontalLayout_3.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.arable_label = QtWidgets.QLabel(self.layoutWidget_6)
font = QtGui.QFont()
font.setPointSize(12)
self.arable_label.setFont(font)
self.arable_label.setObjectName("arable_label")
self.horizontalLayout_3.addWidget(self.arable_label)
self.arab_value = QtWidgets.QDoubleSpinBox(self.layoutWidget_6)
self.arab_value.setSingleStep(0.05)
self.arab_value.setObjectName("arab_value")
self.horizontalLayout_3.addWidget(self.arab_value)
self.layoutWidget_7 = QtWidgets.QWidget(self.groupBox)
self.layoutWidget_7.setGeometry(QtCore.QRect(0, 110, 234, 26))
self.layoutWidget_7.setObjectName("layoutWidget_7")
self.horizontalLayout_4 = QtWidgets.QHBoxLayout(self.layoutWidget_7)
self.horizontalLayout_4.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.woodl_label = QtWidgets.QLabel(self.layoutWidget_7)
font = QtGui.QFont()
font.setPointSize(12)
self.woodl_label.setFont(font)
self.woodl_label.setObjectName("woodl_label")
self.horizontalLayout_4.addWidget(self.woodl_label)
self.wood_value = QtWidgets.QDoubleSpinBox(self.layoutWidget_7)
self.wood_value.setSingleStep(0.05)
self.wood_value.setObjectName("wood_value")
self.horizontalLayout_4.addWidget(self.wood_value)
self.layoutWidget_8 = QtWidgets.QWidget(self.groupBox)
self.layoutWidget_8.setGeometry(QtCore.QRect(0, 140, 234, 26))
self.layoutWidget_8.setObjectName("layoutWidget_8")
self.horizontalLayout_5 = QtWidgets.QHBoxLayout(self.layoutWidget_8)
self.horizontalLayout_5.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_5.setObjectName("horizontalLayout_5")
self.mount_label = QtWidgets.QLabel(self.layoutWidget_8)
font = QtGui.QFont()
font.setPointSize(12)
self.mount_label.setFont(font)
self.mount_label.setObjectName("mount_label")
self.horizontalLayout_5.addWidget(self.mount_label)
self.mount_value = QtWidgets.QDoubleSpinBox(self.layoutWidget_8)
self.mount_value.setSingleStep(0.05)
self.mount_value.setObjectName("mount_value")
self.horizontalLayout_5.addWidget(self.mount_value)
self.start_butt = QtWidgets.QPushButton(self.groupBox)
self.start_butt.setGeometry(QtCore.QRect(50, 290, 113, 32))
self.start_butt.setObjectName("start_butt")
self.landuse_label = QtWidgets.QLabel(self.groupBox)
self.landuse_label.setGeometry(QtCore.QRect(20, 0, 201, 21))
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(18)
self.landuse_label.setFont(font)
self.landuse_label.setLayoutDirection(QtCore.Qt.LeftToRight)
self.landuse_label.setMidLineWidth(0)
self.landuse_label.setObjectName("landuse_label")
self.increase_label = QtWidgets.QLabel(self.groupBox)
self.increase_label.setGeometry(QtCore.QRect(20, 210, 201, 21))
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(18)
self.increase_label.setFont(font)
self.increase_label.setLayoutDirection(QtCore.Qt.LeftToRight)
self.increase_label.setMidLineWidth(0)
self.increase_label.setObjectName("increase_label")
self.rainfall_value = QtWidgets.QDoubleSpinBox(self.groupBox)
self.rainfall_value.setGeometry(QtCore.QRect(50, 240, 110, 24))
self.rainfall_value.setDecimals(1)
self.rainfall_value.setSingleStep(1.0)
self.rainfall_value.setObjectName("rainfall_value")
self.layoutWidget_9 = QtWidgets.QWidget(self.groupBox)
self.layoutWidget_9.setGeometry(QtCore.QRect(0, 170, 234, 26))
self.layoutWidget_9.setObjectName("layoutWidget_9")
self.horizontalLayout_6 = QtWidgets.QHBoxLayout(self.layoutWidget_9)
self.horizontalLayout_6.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_6.setObjectName("horizontalLayout_6")
# Here is the code for the LCD Number
# -----------------------------------------------------------
self.total_label = QtWidgets.QLabel(self.layoutWidget_9)
font = QtGui.QFont()
font.setPointSize(12)
self.total_label.setFont(font)
self.total_label.setObjectName("total_label")
self.horizontalLayout_6.addWidget(self.total_label)
self.total_sum = QtWidgets.QLCDNumber(self.layoutWidget_9)
font = QtGui.QFont()
font.setPointSize(10)
self.total_sum.setFont(font)
self.total_sum.setSegmentStyle(QtWidgets.QLCDNumber.Flat)
self.total_sum.setProperty("value", 0.0)
self.total_sum.setObjectName("total_sum")
self.horizontalLayout_6.addWidget(self.total_sum)
# -----------------------------------------------------------
self.layoutWidget_10 = QtWidgets.QWidget(self.groupBox)
self.layoutWidget_10.setGeometry(QtCore.QRect(0, 20, 234, 26))
self.layoutWidget_10.setObjectName("layoutWidget_10")
self.horizontalLayout_7 = QtWidgets.QHBoxLayout(self.layoutWidget_10)
self.horizontalLayout_7.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_7.setObjectName("horizontalLayout_7")
self.urban_label = QtWidgets.QLabel(self.layoutWidget_10)
font = QtGui.QFont()
font.setPointSize(12)
self.urban_label.setFont(font)
self.urban_label.setObjectName("urban_label")
self.horizontalLayout_7.addWidget(self.urban_label)
self.urban_value = QtWidgets.QDoubleSpinBox(self.layoutWidget_10)
self.urban_value.setSingleStep(0.05)
self.urban_value.setObjectName("urban_value")
self.horizontalLayout_7.addWidget(self.urban_value)
self.powered_by_label = QtWidgets.QLabel(self.tab)
self.powered_by_label.setGeometry(QtCore.QRect(460, 570, 111, 16))
font = QtGui.QFont()
font.setPointSize(11)
self.powered_by_label.setFont(font)
self.powered_by_label.setObjectName("powered_by_label")
self.landuse_label_2 = QtWidgets.QLabel(self.tab)
self.landuse_label_2.setGeometry(QtCore.QRect(330, 10, 421, 21))
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(18)
self.landuse_label_2.setFont(font)
self.landuse_label_2.setLayoutDirection(QtCore.Qt.LeftToRight)
self.landuse_label_2.setMidLineWidth(0)
self.landuse_label_2.setObjectName("landuse_label_2")
self.hydrograph_widget = QtWidgets.QGroupBox(self.tab)
self.hydrograph_widget.setGeometry(QtCore.QRect(280, 60, 711, 501))
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(14)
self.hydrograph_widget.setFont(font)
self.hydrograph_widget.setObjectName("hydrograph_widget")
self.plot_widget = QtWidgets.QWidget(self.hydrograph_widget)
self.plot_widget.setGeometry(QtCore.QRect(10, 30, 691, 461))
self.plot_widget.setObjectName("plot_widget")
self.tabWidget.addTab(self.tab, "")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1039, 22))
self.menubar.setObjectName("menubar")
self.menuMenu = QtWidgets.QMenu(self.menubar)
self.menuMenu.setObjectName("menuMenu")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.actionClose = QtWidgets.QAction(MainWindow)
self.actionClose.setCheckable(False)
self.actionClose.setObjectName("actionClose")
self.menuMenu.addAction(self.actionClose)
self.menubar.addAction(self.menuMenu.menuAction())
self.retranslateUi(MainWindow)
self.tabWidget.setCurrentIndex(0)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
MainWindow.setTabOrder(self.urban_value, self.grass_value)
MainWindow.setTabOrder(self.grass_value, self.arab_value)
MainWindow.setTabOrder(self.arab_value, self.wood_value)
MainWindow.setTabOrder(self.wood_value, self.mount_value)
MainWindow.setTabOrder(self.mount_value, self.rainfall_value)
MainWindow.setTabOrder(self.rainfall_value, self.start_butt)
MainWindow.setTabOrder(self.start_butt, self.tabWidget)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.grass_label.setText(_translate("MainWindow", "Grassland"))
self.arable_label.setText(_translate("MainWindow", "Arable"))
self.woodl_label.setText(_translate("MainWindow", "Woodland"))
self.mount_label.setText(_translate("MainWindow", "Mountain"))
self.start_butt.setText(_translate("MainWindow", "Start"))
self.landuse_label.setText(_translate("MainWindow", "Land Use Coverage (%)"))
self.increase_label.setText(_translate("MainWindow", "Increase in Rainfall (%)"))
self.total_label.setText(_translate("MainWindow", "Total"))
self.urban_label.setText(_translate("MainWindow", "Urban"))
self.powered_by_label.setText(_translate("MainWindow", "Powered by Group 1"))
self.landuse_label_2.setText(_translate("MainWindow", "Hydrological Modelling for the Ouseburn Catchment"))
self.hydrograph_widget.setTitle(_translate("MainWindow", "Hydrograph"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _translate("MainWindow", "HydroModel v.1.0"))
self.menuMenu.setTitle(_translate("MainWindow", "Menu"))
self.actionClose.setText(_translate("MainWindow", "Close"))
#---------------------------------------------------------------------
# Here is my code for updating the LCDNumber
def all_inputs(self):
urban_inp = self.urban_value.value()
grass_inp = self.grass_value.value()
arab_inp = self.arab_value.value()
wood_inp = self.wood_value.value()
mount_inp = self.mount_value.value()
total = urban_inp + grass_inp + arab_inp + wood_inp + mount_inp
self.total_sum.display(total)
#---------------------------------------------------------------------
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_())
QDoubleSpinBox::valueChanged(double d)
This signal is emitted whenever the spin box's value is changed.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1039, 654)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.tabWidget = QtWidgets.QTabWidget(self.centralwidget)
self.tabWidget.setGeometry(QtCore.QRect(10, 0, 1001, 621))
self.tabWidget.setObjectName("tabWidget")
self.tab = QtWidgets.QWidget()
self.tab.setObjectName("tab")
self.groupBox = QtWidgets.QGroupBox(self.tab)
self.groupBox.setGeometry(QtCore.QRect(10, 40, 241, 521))
font = QtGui.QFont()
font.setPointSize(11)
self.groupBox.setFont(font)
self.groupBox.setTitle("")
self.groupBox.setObjectName("groupBox")
self.layoutWidget_5 = QtWidgets.QWidget(self.groupBox)
self.layoutWidget_5.setGeometry(QtCore.QRect(0, 50, 234, 26))
self.layoutWidget_5.setObjectName("layoutWidget_5")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.layoutWidget_5)
self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.grass_label = QtWidgets.QLabel(self.layoutWidget_5)
font = QtGui.QFont()
font.setPointSize(12)
self.grass_label.setFont(font)
self.grass_label.setObjectName("grass_label")
self.horizontalLayout_2.addWidget(self.grass_label)
self.grass_value = QtWidgets.QDoubleSpinBox(self.layoutWidget_5)
self.grass_value.setSingleStep(0.05)
self.grass_value.setObjectName("grass_value")
self.horizontalLayout_2.addWidget(self.grass_value)
self.layoutWidget_6 = QtWidgets.QWidget(self.groupBox)
self.layoutWidget_6.setGeometry(QtCore.QRect(0, 80, 234, 26))
self.layoutWidget_6.setObjectName("layoutWidget_6")
self.horizontalLayout_3 = QtWidgets.QHBoxLayout(self.layoutWidget_6)
self.horizontalLayout_3.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.arable_label = QtWidgets.QLabel(self.layoutWidget_6)
font = QtGui.QFont()
font.setPointSize(12)
self.arable_label.setFont(font)
self.arable_label.setObjectName("arable_label")
self.horizontalLayout_3.addWidget(self.arable_label)
self.arab_value = QtWidgets.QDoubleSpinBox(self.layoutWidget_6)
self.arab_value.setSingleStep(0.05)
self.arab_value.setObjectName("arab_value")
self.horizontalLayout_3.addWidget(self.arab_value)
self.layoutWidget_7 = QtWidgets.QWidget(self.groupBox)
self.layoutWidget_7.setGeometry(QtCore.QRect(0, 110, 234, 26))
self.layoutWidget_7.setObjectName("layoutWidget_7")
self.horizontalLayout_4 = QtWidgets.QHBoxLayout(self.layoutWidget_7)
self.horizontalLayout_4.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.woodl_label = QtWidgets.QLabel(self.layoutWidget_7)
font = QtGui.QFont()
font.setPointSize(12)
self.woodl_label.setFont(font)
self.woodl_label.setObjectName("woodl_label")
self.horizontalLayout_4.addWidget(self.woodl_label)
self.wood_value = QtWidgets.QDoubleSpinBox(self.layoutWidget_7)
self.wood_value.setSingleStep(0.05)
self.wood_value.setObjectName("wood_value")
self.horizontalLayout_4.addWidget(self.wood_value)
self.layoutWidget_8 = QtWidgets.QWidget(self.groupBox)
self.layoutWidget_8.setGeometry(QtCore.QRect(0, 140, 234, 26))
self.layoutWidget_8.setObjectName("layoutWidget_8")
self.horizontalLayout_5 = QtWidgets.QHBoxLayout(self.layoutWidget_8)
self.horizontalLayout_5.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_5.setObjectName("horizontalLayout_5")
self.mount_label = QtWidgets.QLabel(self.layoutWidget_8)
font = QtGui.QFont()
font.setPointSize(12)
self.mount_label.setFont(font)
self.mount_label.setObjectName("mount_label")
self.horizontalLayout_5.addWidget(self.mount_label)
self.mount_value = QtWidgets.QDoubleSpinBox(self.layoutWidget_8)
self.mount_value.setSingleStep(0.05)
self.mount_value.setObjectName("mount_value")
self.horizontalLayout_5.addWidget(self.mount_value)
self.start_butt = QtWidgets.QPushButton(self.groupBox)
self.start_butt.setGeometry(QtCore.QRect(50, 290, 113, 32))
self.start_butt.setObjectName("start_butt")
self.landuse_label = QtWidgets.QLabel(self.groupBox)
self.landuse_label.setGeometry(QtCore.QRect(20, 0, 201, 21))
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(18)
self.landuse_label.setFont(font)
self.landuse_label.setLayoutDirection(QtCore.Qt.LeftToRight)
self.landuse_label.setMidLineWidth(0)
self.landuse_label.setObjectName("landuse_label")
self.increase_label = QtWidgets.QLabel(self.groupBox)
self.increase_label.setGeometry(QtCore.QRect(20, 210, 201, 21))
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(18)
self.increase_label.setFont(font)
self.increase_label.setLayoutDirection(QtCore.Qt.LeftToRight)
self.increase_label.setMidLineWidth(0)
self.increase_label.setObjectName("increase_label")
self.rainfall_value = QtWidgets.QDoubleSpinBox(self.groupBox)
self.rainfall_value.setGeometry(QtCore.QRect(50, 240, 110, 24))
self.rainfall_value.setDecimals(1)
self.rainfall_value.setSingleStep(1.0)
self.rainfall_value.setObjectName("rainfall_value")
self.layoutWidget_9 = QtWidgets.QWidget(self.groupBox)
self.layoutWidget_9.setGeometry(QtCore.QRect(0, 170, 234, 26))
self.layoutWidget_9.setObjectName("layoutWidget_9")
self.horizontalLayout_6 = QtWidgets.QHBoxLayout(self.layoutWidget_9)
self.horizontalLayout_6.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_6.setObjectName("horizontalLayout_6")
# Here is the code for the LCD Number
# -----------------------------------------------------------
self.total_label = QtWidgets.QLabel(self.layoutWidget_9)
font = QtGui.QFont()
font.setPointSize(12)
self.total_label.setFont(font)
self.total_label.setObjectName("total_label")
self.horizontalLayout_6.addWidget(self.total_label)
self.total_sum = QtWidgets.QLCDNumber(self.layoutWidget_9)
font = QtGui.QFont()
font.setPointSize(10)
self.total_sum.setFont(font)
self.total_sum.setSegmentStyle(QtWidgets.QLCDNumber.Flat)
self.total_sum.setProperty("value", 0.0)
self.total_sum.setObjectName("total_sum")
self.horizontalLayout_6.addWidget(self.total_sum)
# -----------------------------------------------------------
self.layoutWidget_10 = QtWidgets.QWidget(self.groupBox)
self.layoutWidget_10.setGeometry(QtCore.QRect(0, 20, 234, 26))
self.layoutWidget_10.setObjectName("layoutWidget_10")
self.horizontalLayout_7 = QtWidgets.QHBoxLayout(self.layoutWidget_10)
self.horizontalLayout_7.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_7.setObjectName("horizontalLayout_7")
self.urban_label = QtWidgets.QLabel(self.layoutWidget_10)
font = QtGui.QFont()
font.setPointSize(12)
self.urban_label.setFont(font)
self.urban_label.setObjectName("urban_label")
self.horizontalLayout_7.addWidget(self.urban_label)
self.urban_value = QtWidgets.QDoubleSpinBox(self.layoutWidget_10)
self.urban_value.setSingleStep(0.05)
self.urban_value.setObjectName("urban_value")
self.horizontalLayout_7.addWidget(self.urban_value)
self.powered_by_label = QtWidgets.QLabel(self.tab)
self.powered_by_label.setGeometry(QtCore.QRect(460, 570, 111, 16))
font = QtGui.QFont()
font.setPointSize(11)
self.powered_by_label.setFont(font)
self.powered_by_label.setObjectName("powered_by_label")
self.landuse_label_2 = QtWidgets.QLabel(self.tab)
self.landuse_label_2.setGeometry(QtCore.QRect(330, 10, 421, 21))
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(18)
self.landuse_label_2.setFont(font)
self.landuse_label_2.setLayoutDirection(QtCore.Qt.LeftToRight)
self.landuse_label_2.setMidLineWidth(0)
self.landuse_label_2.setObjectName("landuse_label_2")
self.hydrograph_widget = QtWidgets.QGroupBox(self.tab)
self.hydrograph_widget.setGeometry(QtCore.QRect(280, 60, 711, 501))
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(14)
self.hydrograph_widget.setFont(font)
self.hydrograph_widget.setObjectName("hydrograph_widget")
self.plot_widget = QtWidgets.QWidget(self.hydrograph_widget)
self.plot_widget.setGeometry(QtCore.QRect(10, 30, 691, 461))
self.plot_widget.setObjectName("plot_widget")
self.tabWidget.addTab(self.tab, "")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1039, 22))
self.menubar.setObjectName("menubar")
self.menuMenu = QtWidgets.QMenu(self.menubar)
self.menuMenu.setObjectName("menuMenu")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.actionClose = QtWidgets.QAction(MainWindow)
self.actionClose.setCheckable(False)
self.actionClose.setObjectName("actionClose")
self.menuMenu.addAction(self.actionClose)
self.menubar.addAction(self.menuMenu.menuAction())
self.retranslateUi(MainWindow)
self.tabWidget.setCurrentIndex(0)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
MainWindow.setTabOrder(self.urban_value, self.grass_value)
MainWindow.setTabOrder(self.grass_value, self.arab_value)
MainWindow.setTabOrder(self.arab_value, self.wood_value)
MainWindow.setTabOrder(self.wood_value, self.mount_value)
MainWindow.setTabOrder(self.mount_value, self.rainfall_value)
MainWindow.setTabOrder(self.rainfall_value, self.start_butt)
MainWindow.setTabOrder(self.start_butt, self.tabWidget)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.grass_label.setText(_translate("MainWindow", "Grassland"))
self.arable_label.setText(_translate("MainWindow", "Arable"))
self.woodl_label.setText(_translate("MainWindow", "Woodland"))
self.mount_label.setText(_translate("MainWindow", "Mountain"))
self.start_butt.setText(_translate("MainWindow", "Start"))
self.landuse_label.setText(_translate("MainWindow", "Land Use Coverage (%)"))
self.increase_label.setText(_translate("MainWindow", "Increase in Rainfall (%)"))
self.total_label.setText(_translate("MainWindow", "Total"))
self.urban_label.setText(_translate("MainWindow", "Urban"))
self.powered_by_label.setText(_translate("MainWindow", "Powered by Group 1"))
self.landuse_label_2.setText(_translate("MainWindow", "Hydrological Modelling for the Ouseburn Catchment"))
self.hydrograph_widget.setTitle(_translate("MainWindow", "Hydrograph"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _translate("MainWindow", "HydroModel v.1.0"))
self.menuMenu.setTitle(_translate("MainWindow", "Menu"))
self.actionClose.setText(_translate("MainWindow", "Close"))
class Example(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self):
super(Example, self).__init__()
self.setupUi(self)
self.urban_value.valueChanged.connect(self.all_inputs) # +
self.grass_value.valueChanged.connect(self.all_inputs) # +
self.arab_value.valueChanged.connect(self.all_inputs) # +
self.wood_value.valueChanged.connect(self.all_inputs) # +
self.mount_value.valueChanged.connect(self.all_inputs) # +
# Here is my code for updating the LCDNumber
def all_inputs(self):
urban_inp = self.urban_value.value()
grass_inp = self.grass_value.value()
arab_inp = self.arab_value.value()
wood_inp = self.wood_value.value()
mount_inp = self.mount_value.value()
total = urban_inp + grass_inp + arab_inp + wood_inp + mount_inp
self.total_sum.display(total)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
w = Example()
w.show()
sys.exit(app.exec_())
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_())