I am trying to get the x axis to fill the entire of the graphics view.
What I have now (the x axis stops around two thirds of the way of the graphics view:
what I am trying to acheive:
I have tried plot.setXRange() with zero padding but that just changes the x axis limits.
I am also unsure about why I cannot see the origin (the x and y axis does not intercept)
Just in case, here is the generated python file from QT designer.ui:
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1131, 890)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.labelCh1 = QtWidgets.QLabel(self.centralwidget)
self.labelCh1.setGeometry(QtCore.QRect(10, 100, 31, 51))
self.labelCh1.setObjectName("labelCh1")
self.labelCh2 = QtWidgets.QLabel(self.centralwidget)
self.labelCh2.setGeometry(QtCore.QRect(10, 190, 31, 51))
self.labelCh2.setObjectName("labelCh2")
self.labelCh3 = QtWidgets.QLabel(self.centralwidget)
self.labelCh3.setGeometry(QtCore.QRect(10, 290, 31, 51))
self.labelCh3.setObjectName("labelCh3")
self.layoutWidget = QtWidgets.QWidget(self.centralwidget)
self.layoutWidget.setGeometry(QtCore.QRect(50, 80, 1051, 747))
self.layoutWidget.setObjectName("layoutWidget")
self.gridLayout = QtWidgets.QGridLayout(self.layoutWidget)
self.gridLayout.setSizeConstraint(QtWidgets.QLayout.SetDefaultConstraint)
self.gridLayout.setContentsMargins(0, 0, 0, 0)
self.gridLayout.setHorizontalSpacing(0)
self.gridLayout.setVerticalSpacing(7)
self.gridLayout.setObjectName("gridLayout")
self.PlotWidgetCh6 = PlotWidget(self.layoutWidget)
self.PlotWidgetCh6.setObjectName("PlotWidgetCh6")
self.gridLayout.addWidget(self.PlotWidgetCh6, 5, 0, 1, 1)
self.PlotWidgetCh5 = PlotWidget(self.layoutWidget)
self.PlotWidgetCh5.setObjectName("PlotWidgetCh5")
self.gridLayout.addWidget(self.PlotWidgetCh5, 4, 0, 1, 1)
self.PlotWidgetCh2 = PlotWidget(self.layoutWidget)
self.PlotWidgetCh2.setObjectName("PlotWidgetCh2")
self.gridLayout.addWidget(self.PlotWidgetCh2, 1, 0, 1, 1)
self.PlotWidgetCh7 = PlotWidget(self.layoutWidget)
self.PlotWidgetCh7.setObjectName("PlotWidgetCh7")
self.gridLayout.addWidget(self.PlotWidgetCh7, 6, 0, 1, 1)
self.PlotWidgetCh1 = PlotWidget(self.layoutWidget)
self.PlotWidgetCh1.setObjectName("PlotWidgetCh1")
self.gridLayout.addWidget(self.PlotWidgetCh1, 0, 0, 1, 1)
self.PlotWidgetCh3 = PlotWidget(self.layoutWidget)
self.PlotWidgetCh3.setObjectName("PlotWidgetCh3")
self.gridLayout.addWidget(self.PlotWidgetCh3, 2, 0, 1, 1)
self.PlotWidgetCh4 = PlotWidget(self.layoutWidget)
self.PlotWidgetCh4.setObjectName("PlotWidgetCh4")
self.gridLayout.addWidget(self.PlotWidgetCh4, 3, 0, 1, 1)
self.PlotWidgetCh8 = PlotWidget(self.layoutWidget)
self.PlotWidgetCh8.setObjectName("PlotWidgetCh8")
self.gridLayout.addWidget(self.PlotWidgetCh8, 7, 0, 1, 1)
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(10, 0, 81, 71))
self.label.setText("")
self.label.setPixmap(QtGui.QPixmap("../OneDrive - AB Dynamics Ltd/Desktop/brainpatch3.png"))
self.label.setObjectName("label")
self.labelCh3_2 = QtWidgets.QLabel(self.centralwidget)
self.labelCh3_2.setGeometry(QtCore.QRect(10, 380, 31, 51))
self.labelCh3_2.setObjectName("labelCh3_2")
self.labelCh3_3 = QtWidgets.QLabel(self.centralwidget)
self.labelCh3_3.setGeometry(QtCore.QRect(10, 480, 31, 51))
self.labelCh3_3.setObjectName("labelCh3_3")
self.labelCh3_4 = QtWidgets.QLabel(self.centralwidget)
self.labelCh3_4.setGeometry(QtCore.QRect(10, 570, 31, 51))
self.labelCh3_4.setObjectName("labelCh3_4")
self.labelCh3_5 = QtWidgets.QLabel(self.centralwidget)
self.labelCh3_5.setGeometry(QtCore.QRect(10, 660, 31, 51))
self.labelCh3_5.setObjectName("labelCh3_5")
self.labelCh3_6 = QtWidgets.QLabel(self.centralwidget)
self.labelCh3_6.setGeometry(QtCore.QRect(10, 760, 31, 51))
self.labelCh3_6.setObjectName("labelCh3_6")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(980, 10, 111, 51))
self.pushButton.setObjectName("pushButton")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(710, 10, 201, 51))
font = QtGui.QFont()
font.setPointSize(12)
self.label_2.setFont(font)
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(10, 0, 81, 71))
self.label_3.setText("")
self.label_3.setPixmap(QtGui.QPixmap("logo.png"))
self.label_3.setObjectName("label_3")
self.numOfChBox = QtWidgets.QSpinBox(self.centralwidget)
self.numOfChBox.setGeometry(QtCore.QRect(920, 10, 51, 51))
font = QtGui.QFont()
font.setPointSize(16)
font.setBold(True)
font.setWeight(75)
self.numOfChBox.setFont(font)
self.numOfChBox.setObjectName("numOfChBox")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1131, 26))
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)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.labelCh1.setText(_translate("MainWindow", "Ch 1"))
self.labelCh2.setText(_translate("MainWindow", "Ch 2"))
self.labelCh3.setText(_translate("MainWindow", "Ch 3"))
self.labelCh3_2.setText(_translate("MainWindow", "Ch 4"))
self.labelCh3_3.setText(_translate("MainWindow", "Ch 5"))
self.labelCh3_4.setText(_translate("MainWindow", "Ch 6"))
self.labelCh3_5.setText(_translate("MainWindow", "Ch 7"))
self.labelCh3_6.setText(_translate("MainWindow", "Ch 8"))
self.pushButton.setText(_translate("MainWindow", "Start/Stop"))
self.label_2.setText(_translate("MainWindow", "Number Of Channels:"))
from pyqtgraph import PlotWidget
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_())
Any suggestions much appreciated.
Thanks in advance,
Will
Related
This is a GUI where I plot data from serial communication.
I want to add an AutoPan for my GUI but I don't know how.
I read there is an autopan in Viewbox but don't know how to implement it.
The option of Autopan is available when I launch the gui buy right clicking on the gui and selectign it manually but I want it to be enabled by default .
from PyQt5 import QtCore, QtGui, QtWidgets
import pyqtgraph as pg
from random import randint
import serial
ser = serial.Serial('COM5',115200)
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(769, 509)
MainWindow.setStyleSheet("\n""background-color: rgb(212, 212, 212);")
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.graphicsView = PlotWidget(self.centralwidget)
self.graphicsView.setGeometry(QtCore.QRect(80, 110, 561, 271))
self.graphicsView.setObjectName("graphicsView")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(260, 30, 211, 31))
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(20, 10, 151, 80))
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(650, 110, 61, 21))
self.label_3.setObjectName("label_3")
self.label_4 = QtWidgets.QLabel(self.centralwidget)
self.label_4.setGeometry(QtCore.QRect(650, 210, 121, 21))
self.label_4.setObjectName("label_4")
self.comboBox = QtWidgets.QComboBox(self.centralwidget)
self.comboBox.setGeometry(QtCore.QRect(650, 140, 69, 22))
self.comboBox.setStyleSheet("background-color: rgb(255, 255, 255);")
self.comboBox.setEditable(False)
self.comboBox.setObjectName("comboBox")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox_2 = QtWidgets.QComboBox(self.centralwidget)
self.comboBox_2.setGeometry(QtCore.QRect(650, 250, 69, 22))
self.comboBox_2.setStyleSheet("background-color: rgb(255, 255, 255);")
self.comboBox_2.setEditable(False)
self.comboBox_2.setObjectName("comboBox_2")
self.comboBox_2.addItem("")
self.comboBox_2.addItem("")
self.comboBox_2.addItem("")
self.splitter = QtWidgets.QSplitter(self.centralwidget)
self.splitter.setGeometry(QtCore.QRect(80, 410, 561, 51))
self.splitter.setOrientation(QtCore.Qt.Horizontal)
self.splitter.setObjectName("splitter")
self.pushButton = QtWidgets.QPushButton(self.splitter)
font = QtGui.QFont()
font.setBold(True)
font.setWeight(75)
self.pushButton.setFont(font)
self.pushButton.setStyleSheet("background-color: rgb(255, 255, 210);")
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(self.splitter)
font = QtGui.QFont()
font.setBold(True)
font.setWeight(75)
self.pushButton_2.setFont(font)
self.pushButton_2.setStyleSheet("background-color: rgb(255, 255, 210);")
self.pushButton_2.setObjectName("pushButton_2")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 769, 21))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.graphicsView.setBackground('w')
self.retranslateUi(MainWindow)
self.comboBox.setCurrentIndex(1)
self.comboBox_2.setCurrentIndex(2)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Queen Monitor"))
self.label.setText(_translate("MainWindow", "<html><head/><body><p><span style=\" font-size:18pt; font-weight:600;\">QUEEN MONITOR</span></p></body></html>"))
self.label_2.setText(_translate("MainWindow", "<html><head/><body><p><img src=\":/rf/queen.png\"/></p></body></html>"))
self.label_3.setText(_translate("MainWindow", "<html><head/><body><p><span style=\" font-weight:600;\">Baud Rate</span></p></body></html>"))
self.label_4.setText(_translate("MainWindow", "<html><head/><body><p><span style=\" font-weight:600;\">Sampling Frequency</span></p></body></html>"))
self.comboBox.setItemText(0, _translate("MainWindow", "4800"))
self.comboBox.setItemText(1, _translate("MainWindow", "115200"))
self.comboBox_2.setItemText(0, _translate("MainWindow", ".... Hz"))
self.comboBox_2.setItemText(1, _translate("MainWindow", ".... Hz"))
self.comboBox_2.setItemText(2, _translate("MainWindow", ".... Hz"))
self.pushButton.setText(_translate("MainWindow", "START"))
self.pushButton_2.setText(_translate("MainWindow", "CLEAR"))
self.pushButton.clicked.connect(lambda:self.start())
self.pushButton_2.clicked.connect(lambda:self.clear())
self.x = [0]*2 # 100 time points
self.y = [0]*2
pen = pg.mkPen(color=(0, 0, 255))
self.data_line = self.graphicsView.plot(self.x, self.y, pen=pen)
def start(self):
self.timer = QtCore.QTimer()
self.timer.setInterval(1)
self.timer.timeout.connect(self.draw)
self.timer.start()
def draw(self):
"""#self.x = self.x[1:] # Remove the first y element.
self.x.append(self.x[-1] + 1) # Add a new value 1 higher than the last.
#self.y = self.y[1:] # Remove the first
self.y.append( randint(0,200)) # Add a new random value.
self.data_line.setData(self.x, self.y) # Update the data."""
rawData = ser.readline().decode("ascii")
dataSplitted = rawData.split(",")
dataSplitted.pop()
dataSplitted.pop(0)
for self.data_raw in dataSplitted:
self.x.append(self.x[-1] + 1)
self.y.append(int(self.data_raw))
self.data_line.setData(self.x, self.y)
def clear(self):
self.graphicsView.clear()
from pyqtgraph import PlotWidget
import rf_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 wrote a program that adds two numbers entered by the user into QLineEdit.
The result of the addition is output to the console in Pycharm.
How to make the result output to the application itself? (so that the user can see the answer).
I guess that there is some special method for this, but what is it?
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Probnei(object):
def setupUi(self, Probnei):
Probnei.setObjectName("Probnei")
Probnei.resize(439, 309)
self.centralwidget = QtWidgets.QWidget(Probnei)
self.centralwidget.setObjectName("centralwidget")
self.layoutWidget = QtWidgets.QWidget(self.centralwidget)
self.layoutWidget.setGeometry(QtCore.QRect(90, 140, 214, 22))
self.layoutWidget.setObjectName("layoutWidget")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.layoutWidget)
self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.label_2 = QtWidgets.QLabel(self.layoutWidget)
self.label_2.setObjectName("label_2")
self.horizontalLayout_2.addWidget(self.label_2)
self.Second_n = QtWidgets.QLineEdit(self.layoutWidget)
self.Second_n.setObjectName("Second_n")
self.horizontalLayout_2.addWidget(self.Second_n)
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(360, 210, 75, 23))
self.pushButton.setObjectName("pushButton")
self.widget = QtWidgets.QWidget(self.centralwidget)
self.widget.setGeometry(QtCore.QRect(90, 60, 214, 22))
self.widget.setObjectName("widget")
self.horizontalLayout = QtWidgets.QHBoxLayout(self.widget)
self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout.setObjectName("horizontalLayout")
self.label = QtWidgets.QLabel(self.widget)
self.label.setObjectName("label")
self.horizontalLayout.addWidget(self.label)
self.First_n = QtWidgets.QLineEdit(self.widget)
self.First_n.setObjectName("First_n")
self.horizontalLayout.addWidget(self.First_n)
Probnei.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(Probnei)
self.menubar.setGeometry(QtCore.QRect(0, 0, 439, 21))
self.menubar.setObjectName("menubar")
Probnei.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(Probnei)
self.statusbar.setObjectName("statusbar")
Probnei.setStatusBar(self.statusbar)
self.retranslateUi(Probnei)
QtCore.QMetaObject.connectSlotsByName(Probnei)
def retranslateUi(self, Probnei):
_translate = QtCore.QCoreApplication.translate
Probnei.setWindowTitle(_translate("Probnei", "MainWindow"))
self.label_2.setText(_translate("Probnei", "Второе число:"))
self.pushButton.setText(_translate("Probnei", "Посчитать"))
self.label.setText(_translate("Probnei", "Первое число:"))
self.pushButton.clicked.connect(self.cal)
def cal(self, Probnei):
val_1 = self.First_n.text()
val_2 = self.Second_n.text()
res = int(val_1) + int(val_2)
print(res)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Probnei = QtWidgets.QMainWindow()
ui = Ui_Probnei()
ui.setupUi(Probnei)
Probnei.show()
sys.exit(app.exec_())
How to make the result output to the application itself?
It's not magic. You just have to create a widget that will display the answer. Then set the text on that widget when you do the calculation.
self.answerLabel = QtWidgets.QLabel(self.widget)
def cal(self, Probnei):
val_1 = self.First_n.text()
val_2 = self.Second_n.text()
res = int(val_1) + int(val_2)
self.answerLabel.setText(res)
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 a ui in Qt designer and transitioned the .ui file into .py file. However, when I run the python code, The ui does not look the same as in the designer when I run the code. I don't understand why this is happening as I can see all of the elements in the code?
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_FirstWindow(object):
def setupUi(self, FirstWindow):
FirstWindow.setObjectName("FirstWindow")
FirstWindow.resize(400, 300)
self.centralWidget = QtWidgets.QWidget(FirstWindow)
self.centralWidget.setObjectName("centralWidget")
self.welcomelabel = QtWidgets.QLabel(self.centralWidget)
self.welcomelabel.setGeometry(QtCore.QRect(90, 10, 211, 20))
font = QtGui.QFont()
font.setBold(True)
font.setWeight(75)
self.welcomelabel.setFont(font)
self.welcomelabel.setAlignment(QtCore.Qt.AlignCenter)
self.welcomelabel.setObjectName("welcomelabel")
self.pushButton = QtWidgets.QPushButton(self.centralWidget)
self.pushButton.setGeometry(QtCore.QRect(150, 120, 80, 16))
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(self.centralWidget)
self.pushButton_2.setGeometry(QtCore.QRect(290, 120, 80, 16))
self.pushButton_2.setObjectName("pushButton_2")
self.pushButton_3 = QtWidgets.QPushButton(self.centralWidget)
self.pushButton_3.setGeometry(QtCore.QRect(10, 120, 80, 16))
self.pushButton_3.setObjectName("pushButton_3")
self.layoutWidget = QtWidgets.QWidget(self.centralWidget)
self.layoutWidget.setGeometry(QtCore.QRect(50, 50, 168, 54))
self.layoutWidget.setObjectName("layoutWidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.layoutWidget)
self.verticalLayout.setContentsMargins(11, 11, 11, 11)
self.verticalLayout.setSpacing(6)
self.verticalLayout.setObjectName("verticalLayout")
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setContentsMargins(11, 11, 11, 11)
self.horizontalLayout.setSpacing(16)
self.horizontalLayout.setObjectName("horizontalLayout")
self.rowcountlabel = QtWidgets.QLabel(self.layoutWidget)
self.rowcountlabel.setObjectName("rowcountlabel")
self.horizontalLayout.addWidget(self.rowcountlabel)
self.rowcounentry = QtWidgets.QLineEdit(self.layoutWidget)
self.rowcounentry.setObjectName("rowcounentry")
self.horizontalLayout.addWidget(self.rowcounentry)
self.verticalLayout.addLayout(self.horizontalLayout)
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
self.horizontalLayout_2.setContentsMargins(11, 11, 11, 11)
self.horizontalLayout_2.setSpacing(6)
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.columncountlabel = QtWidgets.QLabel(self.layoutWidget)
self.columncountlabel.setObjectName("columncountlabel")
self.horizontalLayout_2.addWidget(self.columncountlabel)
self.ColumnNOentry = QtWidgets.QLineEdit(self.layoutWidget)
self.ColumnNOentry.setObjectName("ColumnNOentry")
self.horizontalLayout_2.addWidget(self.ColumnNOentry)
self.verticalLayout.addLayout(self.horizontalLayout_2)
FirstWindow.setCentralWidget(self.centralWidget)
self.menuBar = QtWidgets.QMenuBar(FirstWindow)
self.menuBar.setGeometry(QtCore.QRect(0, 0, 400, 17))
self.menuBar.setObjectName("menuBar")
FirstWindow.setMenuBar(self.menuBar)
self.mainToolBar = QtWidgets.QToolBar(FirstWindow)
self.mainToolBar.setObjectName("mainToolBar")
FirstWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.mainToolBar)
self.statusBar = QtWidgets.QStatusBar(FirstWindow)
self.statusBar.setObjectName("statusBar")
FirstWindow.setStatusBar(self.statusBar)
self.retranslateUi(FirstWindow)
QtCore.QMetaObject.connectSlotsByName(FirstWindow)
def retranslateUi(self, FirstWindow):
_translate = QtCore.QCoreApplication.translate
FirstWindow.setWindowTitle(_translate("FirstWindow", "FirstWindow"))
self.welcomelabel.setText(_translate("FirstWindow", "<html><head/><body><p><span style=\" font-size:12pt;\">Welcome to the Data Generator</span></p></body></html>"))
self.pushButton.setText(_translate("FirstWindow", "Continue"))
self.pushButton_2.setText(_translate("FirstWindow", "Exit"))
self.pushButton_3.setText(_translate("FirstWindow", "Instructions"))
self.rowcountlabel.setText(_translate("FirstWindow", "<html><head/><body><p><span style=\" font-weight:600;\">How Many Rows? </span></p></body></html>"))
self.columncountlabel.setText(_translate("FirstWindow", "<html><head/><body><p><span style=\" font-weight:600;\">How Many Columns? </span></p></body></html>"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
FirstWindow = QtWidgets.QMainWindow()
ui = Ui_FirstWindow()
ui.setupUi(FirstWindow)
FirstWindow.show()
sys.exit(app.exec_())
I expect this:
but it looks like this:
For some reason you do not put all the widgets in the central widget?
I unfortunately could not see what result you want to get.
Try it:
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_FirstWindow(object):
def setupUi(self, FirstWindow):
FirstWindow.setObjectName("FirstWindow")
FirstWindow.resize(400, 300)
self.centralWidget = QtWidgets.QWidget(FirstWindow)
self.centralWidget.setObjectName("centralWidget")
self.welcomelabel = QtWidgets.QLabel(self.centralWidget)
self.welcomelabel.setGeometry(QtCore.QRect(90, 10, 211, 20))
font = QtGui.QFont()
font.setBold(True)
font.setWeight(75)
self.welcomelabel.setFont(font)
self.welcomelabel.setAlignment(QtCore.Qt.AlignCenter)
self.welcomelabel.setObjectName("welcomelabel")
self.pushButton = QtWidgets.QPushButton(self.centralWidget)
self.pushButton.setGeometry(QtCore.QRect(150, 120, 80, 16))
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(self.centralWidget)
self.pushButton_2.setGeometry(QtCore.QRect(290, 120, 80, 16))
self.pushButton_2.setObjectName("pushButton_2")
self.pushButton_3 = QtWidgets.QPushButton(self.centralWidget)
self.pushButton_3.setGeometry(QtCore.QRect(10, 120, 80, 16))
self.pushButton_3.setObjectName("pushButton_3")
# +++ vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
self.hLayout = QtWidgets.QHBoxLayout()
self.hLayout.setContentsMargins(11, 11, 11, 11)
self.hLayout.setSpacing(6)
self.hLayout.setObjectName("hLayout")
self.hLayout.addWidget(self.pushButton_3)
self.hLayout.addWidget(self.pushButton)
self.hLayout.addWidget(self.pushButton_2)
# +++ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
self.layoutWidget = QtWidgets.QWidget(self.centralWidget)
self.layoutWidget.setGeometry(QtCore.QRect(50, 50, 168, 54))
self.layoutWidget.setObjectName("layoutWidget")
# self.verticalLayout = QtWidgets.QVBoxLayout(self.layoutWidget)
self.verticalLayout = QtWidgets.QVBoxLayout(self.centralWidget) # +++
self.verticalLayout.setContentsMargins(11, 11, 11, 11)
self.verticalLayout.setSpacing(6)
self.verticalLayout.setObjectName("verticalLayout")
self.verticalLayout.addWidget(self.welcomelabel) # +++
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setContentsMargins(11, 11, 11, 11)
self.horizontalLayout.setSpacing(16)
self.horizontalLayout.setObjectName("horizontalLayout")
self.rowcountlabel = QtWidgets.QLabel(self.layoutWidget)
self.rowcountlabel.setObjectName("rowcountlabel")
self.horizontalLayout.addWidget(self.rowcountlabel)
self.rowcounentry = QtWidgets.QLineEdit(self.layoutWidget)
self.rowcounentry.setObjectName("rowcounentry")
self.horizontalLayout.addWidget(self.rowcounentry)
self.verticalLayout.addLayout(self.horizontalLayout)
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
self.horizontalLayout_2.setContentsMargins(11, 11, 11, 11)
self.horizontalLayout_2.setSpacing(6)
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.columncountlabel = QtWidgets.QLabel(self.layoutWidget)
self.columncountlabel.setObjectName("columncountlabel")
self.horizontalLayout_2.addWidget(self.columncountlabel)
self.ColumnNOentry = QtWidgets.QLineEdit(self.layoutWidget)
self.ColumnNOentry.setObjectName("ColumnNOentry")
self.horizontalLayout_2.addWidget(self.ColumnNOentry)
self.verticalLayout.addLayout(self.horizontalLayout_2)
self.verticalLayout.addLayout(self.hLayout) # +++
FirstWindow.setCentralWidget(self.centralWidget)
self.menuBar = QtWidgets.QMenuBar(FirstWindow)
self.menuBar.setGeometry(QtCore.QRect(0, 0, 400, 17))
self.menuBar.setObjectName("menuBar")
FirstWindow.setMenuBar(self.menuBar)
self.mainToolBar = QtWidgets.QToolBar(FirstWindow)
self.mainToolBar.setObjectName("mainToolBar")
FirstWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.mainToolBar)
self.statusBar = QtWidgets.QStatusBar(FirstWindow)
self.statusBar.setObjectName("statusBar")
FirstWindow.setStatusBar(self.statusBar)
self.retranslateUi(FirstWindow)
QtCore.QMetaObject.connectSlotsByName(FirstWindow)
def retranslateUi(self, FirstWindow):
_translate = QtCore.QCoreApplication.translate
FirstWindow.setWindowTitle(_translate("FirstWindow", "FirstWindow"))
self.welcomelabel.setText(_translate("FirstWindow", "<html><head/><body><p><span style=\" font-size:12pt;\">Welcome to the Data Generator</span></p></body></html>"))
self.pushButton.setText(_translate("FirstWindow", "Continue"))
self.pushButton_2.setText(_translate("FirstWindow", "Exit"))
self.pushButton_3.setText(_translate("FirstWindow", "Instructions"))
self.rowcountlabel.setText(_translate("FirstWindow", "<html><head/><body><p><span style=\" font-weight:600;\">How Many Rows ? </span></p></body></html>"))
self.columncountlabel.setText(_translate("FirstWindow", "<html><head/><body><p><span style=\" font-weight:600;\">How Many Columns? </span></p></body></html>"))
class Main(QtWidgets.QMainWindow, Ui_FirstWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
spinbox = Main()
spinbox.show()
sys.exit(app.exec_())