I'm having a QSpinbox inside a QTreeWidget following an approach similar to the approach for a combobox described here https://stackoverflow.com/a/4849010/10220019.
I've read here https://forum.qt.io/topic/103667/qdoublespinbox-why-isn-t-valuechanged-signal-fired-when-content-is-empty/5 that if you use the valueChanged(const QString&)
signal this should fire when you backspace from a number to empty. However this is not the case for me. The only difference I can see between that post and my code is that I use a QSpinBox and not a QDoubleSpinBox but that shouldn't be the problem I guess.
I think I might be connecting the signal wrongly because the behavior I get completely matches the behavior I would expect from valueChanged(int). But I wouldn't know how to write the connect then. Does somebody see the error?
My code is: QTreeWidgetItemSpinBox.h
#pragma once
#pragma warning (push)
#pragma warning (disable: 26451 26495 26498 26439)
#include <QtWidgets/QSpinbox>
#include <QtWidgets/QTreeWidget>
#include <QtWidgets/QToolTip>
#pragma warning (pop)
class QTreeWidgetItemSpinBox :
public QSpinBox
{
Q_OBJECT
public:
QTreeWidgetItemSpinBox(QTreeWidgetItem* treeItem, int column);
public slots:
void validateValue(const QString& input);
private:
QTreeWidgetItem* treeItem;
int column;
};
QTreeWidgetItemSpinBox.cpp
#include "QTreeWidgetItemSpinBox.h"
#include <QtCore/QDebug>
QTreeWidgetItemSpinBox::QTreeWidgetItemSpinBox(QTreeWidgetItem* treeItem, int column)
: treeItem(treeItem), column(column)
{
connect(this, SIGNAL(valueChanged(const QString&)), SLOT(validateValue(const QString&)));
}
void QTreeWidgetItemSpinBox::validateValue(const QString& input)
{
qDebug() << "Called"; //Is called when changed to another number but not if the change is to empty or if I add zeros before a number
}