Look at the slots which handle the TextChanged signal.
Code: Select all
void QAbstractSpinBoxPrivate::_q_editorTextChanged(const QString &t)
void QuantitySpinBox::userInput(const QString & text)
Code: Select all
void QAbstractSpinBoxPrivate::_q_editorTextChanged(const QString &t)
void QuantitySpinBox::userInput(const QString & text)
keyboardTracking variable is inherited along with the get 'keyboardTracking()' and the set 'setKeyboardTracking()' methods. This is how C++ (and globally OOP) works. This means that you can change the value of any instance of QuantitySpinBox. But it appears that QuantitySpinBox makes absolutely no usage of this variable, i.e. its behavior is always the same whatever is the value.uwestoehr wrote: ↑Mon Jun 01, 2020 12:24 pm I must admit, I am confused now. As it is, Gui::QuantitySpinBox behaves in any case as if keyboardTracking=TRUE. To do so, it must have inherited that there is such a property. Thus I thought, inheritance means also the methods to change the inherited properties are inherited too.
As this is not the case, so I will have to implement this to Gui::QuantitySpinBox manually. I'll have a look at the QAbstractButton sources hoping I'll understand what I have to do. I thought that a Qt expert here could give me pointer or already knows what to do.
Try: git commit 15c964400
They shouldn't suffer from this problem because they inherit from QSpinBox and QDoubleSpinBox, respectively. These two Qt classes implement the needed functionality in their private classes.
Code: Select all
QString QAbstractSpinBoxPrivate::textFromValue(const QVariant &) const
QVariant QAbstractSpinBoxPrivate::valueFromText(const QString &) const
Many thanks!
Code: Select all
ui->qsbX->setKeyboardTracking(false);
connect(ui->qsbX, SIGNAL(valueChanged()),
this, SLOT(onXEdit()));
OK, my mistake.
Code: Select all
ui->qsbX->setKeyboardTracking(false);
connect(ui->qsbX, SIGNAL(editingFinished()),
this, SLOT(onXEdit()));
Code: Select all
ui->qsbX->setKeyboardTracking(false);
connect(ui->qsbX, SIGNAL(valueChanged(bool)),
this, SLOT(onXEdit()));
Code: Select all
ui=Gui.UiLoader()
sp=ui.createWidget("Gui::QuantitySpinBox")
sp.setKeyboardTracking(False)
sp.setProperty("unit","mm")
sp.valueChanged.connect(lambda: print(sp.text()))
sp.show()
The editingFinished() signal is only emitted when Enter/Return is pressed. Look at the implementation and documentation of QAbstractSpinBox.ui->qsbX->setKeyboardTracking(false);
connect(ui->qsbX, SIGNAL(editingFinished()),
this, SLOT(onXEdit()));
A signal valueChanged(bool) doesn't even exist. Here you should see a warning in the output window that trying to connect this signal with the slot failed.ui->qsbX->setKeyboardTracking(false);
connect(ui->qsbX, SIGNAL(valueChanged(bool)),
this, SLOT(onXEdit()));