Results 1 to 11 of 11

Thread: catch signal stepDown from doubleSpinBox

  1. #1
    Join Date
    Feb 2008
    Posts
    157
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default catch signal stepDown from doubleSpinBox

    I want to catch teh up and down signals from QAbstractSpinBox within a QDoubleSpinBox instance:
    Qt Code:
    1. connect(doubleSpinBox, SIGNAL(stepDown()), this, SLOT(OnUnitStepDown()));
    2. connect(doubleSpinBox, SIGNAL(stepUp () ), this, SLOT(OnUnitStepUp()));
    To copy to clipboard, switch view to plain text mode 

    however that only results in
    no such Signal QDoubleSpinBox::stepDown()
    ...
    how do I do it then?

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: catch signal stepDown from doubleSpinBox

    stepDown() is a slot. You can not connect to a slot.

  3. #3
    Join Date
    Feb 2008
    Posts
    157
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: catch signal stepDown from doubleSpinBox

    Quote Originally Posted by caduel View Post
    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?

  4. #4
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: catch signal stepDown from doubleSpinBox

    You can subclass the spinbox and override the stepBy() method.
    Apart from that, maybe the valueChanged signal?

  5. #5
    Join Date
    Feb 2008
    Posts
    157
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: catch signal stepDown from doubleSpinBox

    Quote Originally Posted by caduel View Post
    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.

  6. #6
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: catch signal stepDown from doubleSpinBox

    in what way did subclassing not work?

  7. #7
    Join Date
    Feb 2008
    Posts
    157
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: catch signal stepDown from doubleSpinBox

    Quote Originally Posted by caduel View Post
    in what way did subclassing not work?
    Qt Code:
    1. class QScienceLineEdit : public QDoubleSpinBox
    2. {
    3. Q_OBJECT
    4. public:
    5. QScienceLineEdit(QWidget* parent = 0, Qt::WFlags flags = 0);
    6. virtual ~QScienceLineEdit();
    7. ...
    To copy to clipboard, switch view to plain text mode 

    fails at line
    Qt Code:
    1. Q_DECLARE_PRIVATE(QDoubleSpinBox)
    To copy to clipboard, switch view to plain text mode 
    in qspinbox.h

  8. #8
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: catch signal stepDown from doubleSpinBox

    That should not be the case. Can you show us you .pro file, and the complete header file?

  9. #9
    Join Date
    Feb 2008
    Posts
    157
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: catch signal stepDown from doubleSpinBox

    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:
    Qt Code:
    1. class QScienceSpinBox : public QDoubleSpinBox
    2. {
    3. Q_OBJECT
    4. public:
    5. QScienceSpinBox(QWidget * parent = 0);
    6.  
    7. QString textFromValue ( double value ) const;
    8. double valueFromText ( const QString & text ) const;
    9. ...
    10. private slots:
    11. void stepDown();
    12. void stepUp();
    13.  
    14. };
    To copy to clipboard, switch view to plain text mode 

  10. #10
    Join Date
    Nov 2008
    Posts
    142
    Thanks
    3
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: catch signal stepDown from doubleSpinBox

    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.

  11. #11
    Join Date
    Feb 2008
    Posts
    157
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: catch signal stepDown from doubleSpinBox

    Quote Originally Posted by rexi View Post
    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:
    Qt Code:
    1. // overwritten virtual function of QAbstractSpinBox
    2. void QScienceSpinBox::stepBy(int steps)
    3. {
    4. if (steps < 0)
    5. stepDown();
    6. else
    7. stepUp();
    8. }
    9.  
    10. void QScienceSpinBox::stepDown()
    11. {
    12. QSBDEBUG() << "stepDown()";
    13. setValue(value()/10.0);
    14. }
    15.  
    16. void QScienceSpinBox::stepUp()
    17. {
    18. QSBDEBUG() << "stepUp()";
    19. setValue(value()*10.0);
    20. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by pospiech; 3rd January 2009 at 14:55.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.