about QSpinBox, how to make it emit editingFinished signal when click the "up/down" arrow button ??



  • about QSpinBox, how to make it emit editingFinished signal when click the "up/down" arrow button?
    i do want to emit editingFinished signal when edit text, but when i use editingFinished when click the "up/down" arrow button the effect is not what i want...
    i do want this effect:

    1. emit editingFinished signal when edit text.
    2. emit valueChanged signal when click the "up/down" arrow button.


  • @opengpu2
    You can refer this to emit valueChanged signal.
    editingFinished() happens when the spinbox loses focus and when enter is pressed.



  • @Ratzz i know, but i want the effect like this: when i use the single & slot, the signal is emitted when :

    1. when editting, it emit when editingFinished;
    2. when click the "up/down" arrow button, it emit when valueChanged;


  • anyone help?


  • Moderators

    You can connect valueChanged() signal with editingFinished() signal, that's all.



  • As told by Jsulm as well and you can do the following.

    QObject::connect(spinBox,SIGNAL(valueChanged(int)),spinBox,SIGNAL(editFinished()));


  • Moderators

    use this to determine if the user pressed the up or down buttons:

    void MySpinBox::mousePressEvent(QMouseEvent* event)
    {
         QSpinBox::mousePressEvent(event);
    
        QStyleOptionSpinBox opt;
        this->initStyleOption(&opt);
    
        if( this->style()->subControlRect(QStyle::CC_SpinBox, &opt, QStyle::SC_SpinBoxUp).contains(event->pos()) )
            // UP BUTTON PRESSED
        else if( this->style()->subControlRect(QStyle::CC_SpinBox, &opt, QStyle::SC_SpinBoxDown).contains(event->pos()) )
            //DOWN BUTTON PRESSED
    }
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.