I want to share 100 percent value limit to all QDoubleSpinBoxes. If it is possible how to do?
self.SpinBox_one = QtWidgets.QDoubleSpinBox() self.SpinBox_two = QtWidgets.QDoubleSpinBox() self.SpinBox_three = QtWidgets.QDoubleSpinBox() self.SpinBox_four = QtWidgets.QDoubleSpinBox() self.SpinBox_five = QtWidgets.QDoubleSpinBox()
for example i have 5 QDoubleSpinBoxes as above. If i insert 30 in self.SpinBox_one, Remaining is 70, then 70 only should be useful for remaining 4 QDoubleSpinBoxes. And again if i insert 50 in self.SpinBox_two, Remaining should be 20, and it should be useful to remaining QDoubleSpinBoxes. and again if i insert 20 in self.SpinBox_three, remaining is 0. And now remaining QDoubleSpinBoxes are should be 0. Below is my example code:
from PyQt5 import QtWidgets
from PyQt5 import QtCore
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
self.SpinBox_one = QtWidgets.QDoubleSpinBox()
self.SpinBox_two = QtWidgets.QDoubleSpinBox()
self.SpinBox_three = QtWidgets.QDoubleSpinBox()
self.SpinBox_four = QtWidgets.QDoubleSpinBox()
self.SpinBox_five = QtWidgets.QDoubleSpinBox()
form_widget = QtWidgets.QWidget()
form_layout = QtWidgets.QFormLayout(form_widget)
form_layout.addRow("1", self.SpinBox_one)
form_layout.addRow("2", self.SpinBox_two)
form_layout.addRow("3", self.SpinBox_three)
form_layout.addRow("4", self.SpinBox_four)
form_layout.addRow("5", self.SpinBox_five)
form_widget.setFixedSize(form_widget.sizeHint())
central_widget = QtWidgets.QWidget()
self.setCentralWidget(central_widget)
hlay1 = QtWidgets.QHBoxLayout()
hlay1.addWidget(form_widget)
hlay1.addStretch()
vboxlayout = QtWidgets.QVBoxLayout(central_widget)
vboxlayout.addLayout(hlay1)
self.resize(50, 50)
##
self.SpinBox_one.setMaximum(100.00)
#self.SpinBox_two.setMaximum(100.00)
#self.SpinBox_three.setMaximum(100.00)
#self.SpinBox_four.setMaximum(100.00)
#self.SpinBox_five.setMaximum(100.00)
self.SpinBox_one.valueChanged.connect(self.SpinBox_one_changed)
self.SpinBox_two.valueChanged.connect(self.SpinBox_two_changed)
self.SpinBox_three.valueChanged.connect(self.SpinBox_three_changed)
self.SpinBox_four.valueChanged.connect(self.SpinBox_four_changed)
def SpinBox_one_changed(self):
self.SpinBox_two.setMaximum(100 - self.SpinBox_one.value())
def SpinBox_two_changed(self):
self.SpinBox_three.setMaximum(100-self.SpinBox_one.value() - self.SpinBox_two.value())
def SpinBox_three_changed(self):
self.SpinBox_four.setMaximum(100-self.SpinBox_one.value() - self.SpinBox_two.value() - self.SpinBox_three.value())
def SpinBox_four_changed(self):
self.SpinBox_five.setMaximum(100-self.SpinBox_one.value() - self.SpinBox_two.value() - self.SpinBox_three.value() - self.SpinBox_four.value())
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
w = MainWindow()
w.show()
sys.exit(app.exec_())
It is working up to fourth but fifth is not working as expect.