Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

call a function when changing a QSpinBox value [duplicate]

Tags:

python

pyqt

pyqt5

I have 2 QSpinBox'es - horTilesNum and verTilesNum. The value of the horizontal one should always be 1.5 times bigger than the number of the vertical one. So when the value of one of those Spinboxes is changed the value of another Spinbox should be updated. I have 2 functions for that but I don't know how to call them when Spinbox values are chenged

self.horTilesNum= QSpinBox(self)
self.horTilesNum.setRange(2,1000)
self.horTilesNum.setStyleSheet("QSpinBox {"
                                           "width: 30px;"
                                           "}")
self.horTilesNum.move(880, 178)


self.verTilesNum = QSpinBox(self)
self.verTilesNum.setRange(2,1000)
self.verTilesNum.setStyleSheet("QSpinBox {"
                                           "width: 30px;"
                                           "}")
self.verTilesNum.move(880, 203)



def update_hor_tiles_spinbox(self):
    print("horizontal changed")

def update_ver_tiles_spinbox(self):
    print("vertical changed")
like image 495
AndSolomin34 Avatar asked May 07 '26 07:05

AndSolomin34


1 Answers

try this

self.horTilesNum.valueChanged.connect(self.update_hor_tiles_spinbox)
self.verTilesNum.valueChanged.connect(self.update_ver_tiles_spinbox)
like image 56
vic Avatar answered May 09 '26 00:05

vic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!