how can i know whether i click in the region of the UpDownArrow buttons of QDoubleSpinbox or the edit region of the rest area of QDoubleSpinbox ?



  • how can i know whether i click in the region of the UpDownArrow buttons of QDoubleSpinbox or the edit region of the rest area of QDoubleSpinbox ?



  • Hi,
    please tell what you want to achieve to prevent an x-y problem.
    -Michael.


  • Moderators

    @opengpu2

    void MyDoubleSpinBox::mousePressEvent(QMouseEvent* event)
    {
        QDoubleSpinBox::mousePressEvent(event);
    
        QStyleOptionSpinBox opt;
        this->initStyleOption(&opt);
        const QStyle* style = this->style();
        const QPoint pos = event->pos();
     
        if( style->subControlRect(QStyle::CC_SpinBox,&opt,QStyle::SC_SpinBoxUp).contains(pos) )
            //upButton pressed
        else if( style->subControlRect(QStyle::CC_SpinBox,&opt,QStyle::SC_SpinBoxDown).contains(pos) )
            // downButton pressed
        else if( style->subControlRect(QStyle::CC_SpinBox,&opt,QStyle::SC_SpinBoxEditField).contains(pos) )
            // editfield pressed
    }
    

Log in to reply
 

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