(PyQT) How can I make sure values in all following spinboxes are higher than the last
<p>The following is an example of inputs that could potentially be added.</p>

<p>value 0: [&nbsp;&nbsp;&nbsp;&nbsp;   0 ] [ 100 ]
<br>value 1: [ 200 ] [ 300 ]
<br>value 2: [ 400 ] [ 500 ]</p>

<p>The above is correct</p>

<p>value 0: [&nbsp;&nbsp;&nbsp;&nbsp;   0 ] [ 800 ]
<br>value 1: [ 700 ] [ 600 ]
<br>value 2: [ 500 ] [ 400 ]</p>

<p>The above is incorrect: Make sure each value is higher than the last</p>

<p>The code below has each value that the user inputs added to an array. </p>

<pre><code>def val_norm(self, MainWindow, count):
    self.verticalLayout_2 = QtGui.QVBoxLayout()
    self.verticalLayout_2.setMargin(11)
    self.verticalLayout_2.setSpacing(6)
    self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2"))
    self.horizontalLayout_2 = QtGui.QHBoxLayout()
    self.horizontalLayout_2.setMargin(11)
    self.horizontalLayout_2.setSpacing(6)
    self.horizontalLayout_2.setObjectName(_fromUtf8("horizontalLayout_2"))
    self.norm_label = QtGui.QLabel(self.Normalization)
    self.norm_label.setObjectName(_fromUtf8("norm_label"))
    self.horizontalLayout_2.addWidget(self.norm_label)

    self.norm_spinBox_[(count*2)-1] = QtGui.QSpinBox(self.Normalization)    # All the left side boxes
    self.norm_spinBox_[(count*2)] = QtGui.QSpinBox(self.Normalization)      # All the right side boxes

    self.norm_spinBox_[(count*2)-1].setMaximum(1000)                        # set the maximums for the left side
    self.norm_spinBox_[(count*2)].setMaximum(1000)                          # set the maximums for the right side
    self.horizontalLayout_2.addWidget(self.norm_spinBox_[(count*2)-1])      # adding the actual object to UI (left)
    self.horizontalLayout_2.addWidget(self.norm_spinBox_[(count*2)])        # adding the actual object to UI (right)
    self.verticalLayout_2.addLayout(self.horizontalLayout_2)                # setting up layout
    self.verticalLayout.addLayout(self.verticalLayout_2)                    # setting up layout


    # for debugging purposes
    self.norm_spinBox_[(count*2)-1].editingFinished.connect(lambda: print(self.norm_spinBox_[(count*2)-1].text()))
    self.norm_spinBox_[(count*2)].editingFinished.connect(lambda: print(self.norm_spinBox_[(count*2)].text()))

    self.norm_label.setText(_translate("MainWindow", "Value {}".format(self.count), None))
    self.count += 1


    if self.norm_spinBox_[(count*2)-1].text() &gt; self.norm_spinBox_[count*2].text():
        print("That's wrong!")
</code></pre>

<p>I thought that using an if statement would work, but I'm clearly misguided on how I should be approaching this. Correct me if I'm wrong, but I'm thinking it's not working because I'm not connecting the if statement to each box after it's been edited. </p>

<pre><code>if self.norm_spinBox_[(count*2)-1].text() &gt; self.norm_spinBox_[count*2].text():
    print("That's wrong!")
</code></pre>

<p>you could use the <code>valueChanged()</code> signal of <code>QSpinBox</code> to <code>setMinimum()</code> of the following spinboxes according to the value of the former spinbox, so the spinboxes only accept values >= minimum, here a working example:</p>

<pre><code>import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *

class SpinboxWidget(QWidget):
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)
        self.layout = QVBoxLayout()
        # self.signalMapper = QSignalMapper(self)                   
        # self.signalMapper.mapped[str].connect(self.setspbMin)
        self.addSpinboxes(10)                                   # add an arbitrary number of spinboxes
        self.setLayout(self.layout)

    def addSpinboxes(self, n):
        spb = []
        for i in range(n):
            # objectname = 'spinbox_{}'.format(i)
            spinbox = QSpinBox()
            # spinbox.setObjectName(objectname)                 # to identify the spinbox later
            spinbox.setMaximum(100)
            # spinbox.valueChanged.connect(self.signalMapper.map)
            # self.signalMapper.setMapping(spinbox, objectname) # sends the objectname with his mapped() signal
            spb.append(spinbox)                                 # added in edit
            self.layout.addWidget(spinbox)

        for i in range(n-1):
            spb[i].valueChanged.connect(spb[i + 1].setMinimum)

    '''            
    def setspbMin(self, identifier):       
        spinbox = self.findChild(QSpinBox,identifier)           # don't use QObject.sender() see Documentation
        nextIndex = int(identifier.lstrip('spinbox_')) + 1
        nextIdentifier = 'spinbox_{}'.format(nextIndex)
        nextSpinbox = self.findChild(QSpinBox,nextIdentifier)
        try:
            nextSpinbox.setMinimum(spinbox.value()) 
        except AttributeError:
            pass
    '''

if __name__ == '__main__':  
    app = QApplication(sys.argv)
    app.setStyle('plastique')
    widget = SpinboxWidget()
    widget.setWindowTitle('Spinbox Tester')
    widget.show()

sys.exit(app.exec_())
</code></pre>

<p><strong>edit:</strong>
as suggested by ekhumoro signalMapper is not necessary -> outcommented lines are no longer needed. the <code>valueChanged</code>-signal is connected to <code>setMinimum()</code> of the following spinbox. </p>

python pyqt