Add returnPressed signal to spin boxes
This differs from `editingFinished`, which is also triggered when the focus is lost. `returnPressed` is useful if the user is to explicitly confirm the acceptance of the value, for example by means of an Apply button next to the SpinBox. The corresponding signal of the internal QLineEdit cannot be used as access to it is protected. Change-Id: Ie9a146212e6aeac5cc9e4592b1633156323426dd Fixes: QTBUG-99797 Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
This commit is contained in:
parent
e323d46cda
commit
697aad4b8c
@ -112,6 +112,13 @@ using namespace std::chrono_literals;
|
||||
spinbox loses focus and when enter is pressed.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QAbstractSpinBox::returnPressed()
|
||||
\since 6.10
|
||||
|
||||
This signal is emitted when the Return or Enter key is used.
|
||||
*/
|
||||
|
||||
/*!
|
||||
Constructs an abstract spinbox with the given \a parent with default
|
||||
\l wrapping, and \l alignment properties.
|
||||
@ -1053,6 +1060,7 @@ void QAbstractSpinBox::keyPressEvent(QKeyEvent *event)
|
||||
selectAll();
|
||||
event->ignore();
|
||||
emit editingFinished();
|
||||
emit returnPressed();
|
||||
emit d->edit->returnPressed();
|
||||
return;
|
||||
|
||||
|
@ -132,6 +132,7 @@ protected:
|
||||
virtual StepEnabled stepEnabled() const;
|
||||
Q_SIGNALS:
|
||||
void editingFinished();
|
||||
void returnPressed();
|
||||
protected:
|
||||
QAbstractSpinBox(QAbstractSpinBoxPrivate &dd, QWidget *parent = nullptr);
|
||||
|
||||
|
@ -158,6 +158,8 @@ private slots:
|
||||
|
||||
void editingFinished();
|
||||
|
||||
void returnPressed();
|
||||
|
||||
void removeAll();
|
||||
|
||||
void task199226_stateAfterEnter();
|
||||
@ -908,6 +910,15 @@ void tst_QDoubleSpinBox::editingFinished()
|
||||
QCOMPARE(editingFinishedSpy2.size(), 4);
|
||||
}
|
||||
|
||||
void tst_QDoubleSpinBox::returnPressed()
|
||||
{
|
||||
QDoubleSpinBox spinBox;
|
||||
QSignalSpy spyCurrentChanged(&spinBox, &QDoubleSpinBox::returnPressed);
|
||||
spinBox.show();
|
||||
QTest::keyClick(&spinBox, Qt::Key_Return);
|
||||
QCOMPARE(spyCurrentChanged.size(), 1);
|
||||
}
|
||||
|
||||
void tst_QDoubleSpinBox::removeAll()
|
||||
{
|
||||
DoubleSpinBox spin(0);
|
||||
|
@ -169,6 +169,8 @@ private slots:
|
||||
|
||||
void editingFinished();
|
||||
|
||||
void returnPressed();
|
||||
|
||||
void valueFromTextAndValidate_data();
|
||||
void valueFromTextAndValidate();
|
||||
|
||||
@ -991,6 +993,15 @@ void tst_QSpinBox::editingFinished()
|
||||
QCOMPARE(editingFinishedSpy1.size(), 1);
|
||||
}
|
||||
|
||||
void tst_QSpinBox::returnPressed()
|
||||
{
|
||||
QSpinBox spinBox;
|
||||
QSignalSpy spyCurrentChanged(&spinBox, &QSpinBox::returnPressed);
|
||||
spinBox.show();
|
||||
QTest::keyClick(&spinBox, Qt::Key_Return);
|
||||
QCOMPARE(spyCurrentChanged.size(), 1);
|
||||
}
|
||||
|
||||
void tst_QSpinBox::removeAll()
|
||||
{
|
||||
SpinBox spin(0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user