Reputation: 1352
I am trying to find out howto connect a change in QtWidgets.QDoubleSpinBox in using pyqt5 in python to a method. AFAICS QtWidgets.QDoubleSpinBox.valueChanged does not have a connect function anymore (as in PYQT4).
I have tried to search for an answer but I just cant seem to find out how to accomplish this...
Anyone who knows?
EDIT1> Thanks for the reply but I cant see the difference to this:
thanks for your reply, but I cant see the difference to this
self.dsbGR = QtWidgets.QDoubleSpinBox(self.centralwidget)
self.dsbGR.setDecimals(3)
self.dsbGR.setSingleStep(0.1)
self.dsbGR.setProperty("value", 3.0)
self.dsbGR.setObjectName("dsbGR")
self.dsbGR.valueChanged.connect(myfunction)
The last line does not work, there is no connect
method.
Upvotes: 0
Views: 1418
Reputation: 243887
I think the problem is that you are not using the new style of signal and slots connection, in the following example I show its use with the widget QDoubleSpinBox.
from PyQt5 import QtCore, QtGui, QtWidgets
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None):
QtWidgets.QMainWindow.__init__(self, parent)
self.centralwidget = QtWidgets.QWidget(self)
self.setCentralWidget(self.centralwidget)
self.centralWidget().setLayout(QtWidgets.QVBoxLayout())
self.dsbGR = QtWidgets.QDoubleSpinBox(self.centralwidget)
self.dsbGR.setDecimals(3)
self.dsbGR.setSingleStep(0.1)
self.dsbGR.setProperty("value", 3.0)
self.dsbGR.setObjectName("dsbGR")
self.dsbGR.valueChanged.connect(self.onValueChanged)
self.centralWidget().layout().addWidget(self.dsbGR)
def onValueChanged(self, val):
print(val)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
w = MainWindow()
w.show()
sys.exit(app.exec_())
Upvotes: 1