PDA

View Full Version : catch signal stepDown from doubleSpinBox



pospiech
27th November 2008, 18:41
I want to catch teh up and down signals from QAbstractSpinBox within a QDoubleSpinBox instance:


connect(doubleSpinBox, SIGNAL(stepDown()), this, SLOT(OnUnitStepDown()));
connect(doubleSpinBox, SIGNAL(stepUp () ), this, SLOT(OnUnitStepUp()));


however that only results in


no such Signal QDoubleSpinBox::stepDown()
...


how do I do it then?

caduel
27th November 2008, 18:59
stepDown() is a slot. You can not connect to a slot.

pospiech
27th November 2008, 20:04
stepDown() is a slot. You can not connect to a slot.

ok, I have overlooked that. However I need to get a signal upon upper and lower Buttons. Is there any way to implement something that does that?

caduel
27th November 2008, 22:02
You can subclass the spinbox and override the stepBy() method.
Apart from that, maybe the valueChanged signal?

pospiech
28th November 2008, 11:45
You can subclass the spinbox and override the stepBy() method.
Apart from that, maybe the valueChanged signal?

What I need is the buttons. They shall not change the value, I just want to know that they are pressed.

I could also live with a doublespinbox without any buttons and standalone buttons without any edit area.

I tried to subclass from qdoublespinbox, but that does not work.

caduel
28th November 2008, 11:53
in what way did subclassing not work?

pospiech
28th November 2008, 12:33
in what way did subclassing not work?


class QScienceLineEdit : public QDoubleSpinBox
{
Q_OBJECT
public:
QScienceLineEdit(QWidget* parent = 0, Qt::WFlags flags = 0);
virtual ~QScienceLineEdit();
...


fails at line


Q_DECLARE_PRIVATE(QDoubleSpinBox)

in qspinbox.h

caduel
28th November 2008, 14:04
That should not be the case. Can you show us you .pro file, and the complete header file?

pospiech
2nd January 2009, 23:47
Now I tried to subclass from doubleSpinBox again. It works now (new project, dont know why it failed in the old one).

However the slot:
void QScienceSpinBox::stepDown()

is never called if I press up or down arrows.

The code is looking like this:


class QScienceSpinBox : public QDoubleSpinBox
{
Q_OBJECT
public:
QScienceSpinBox(QWidget * parent = 0);

QString textFromValue ( double value ) const;
double valueFromText ( const QString & text ) const;
...
private slots:
void stepDown();
void stepUp();

};

rexi
3rd January 2009, 00:45
Is it only the stepDown slot? The stepUp/Down slots are public in QDoubleSpinBox, and you are redeclaring them as private. Maybe that's causing your problem.

pospiech
3rd January 2009, 12:51
Is it only the stepDown slot? The stepUp/Down slots are public in QDoubleSpinBox, and you are redeclaring them as private. Maybe that's causing your problem.

makeing the slots public changes nothing. The functions are still not called at button up or down.

EDIT:
If I use the correct virtual function it works:


// overwritten virtual function of QAbstractSpinBox
void QScienceSpinBox::stepBy(int steps)
{
if (steps < 0)
stepDown();
else
stepUp();
}

void QScienceSpinBox::stepDown()
{
QSBDEBUG() << "stepDown()";
setValue(value()/10.0);
}

void QScienceSpinBox::stepUp()
{
QSBDEBUG() << "stepUp()";
setValue(value()*10.0);
}