Modify hit box of QRadioButton (SE_RadioButtonClickRect)



  • Hi all,

    currently I'm struggling with the following task: I want slightly increase the hit box around the QRadioButton. (The area where you can activate the button.)

    The "hit box" has several rules to fullfil in QRadioButton::mouseMoveEvent like underMouse or hitButton. The ClickRect is filled in QStyleOption::initFrom aka init by using widget->rect(). Qt doc says in QWidget::rect():
    The rect property equals QRect(0, 0, width(), height()).
    Means that I only need to call for example setMinimumSize, setGeometry or resize to increase it, but for me it doesn't work (from Qt4.7.X up to Qt5.X).

    I also derived QRadioButton and adjusted minimumSizeHint and sizeHint which doesn't had any impact towards the hit box.

    Any ideas?

    Kind regards,
    Mike


  • Lifetime Qt Champion

    Hi,

    Can you show your code ? Without it it's pretty much "Crystal Ball Debugging".


  • Qt Champions 2017

    Hi
    One way is

    #include <QProxyStyle>
    class MyStyle : public QProxyStyle {
      virtual QRect subElementRect(SubElement subElement, const QStyleOption*opt , const QWidget* widget) const override {
        if ( subElement == SE_RadioButtonClickRect && widget)
          return widget->rect();
        else
          return QProxyStyle::subElementRect( subElement,opt,widget) ;
      }
    };
    
    
    ui->radioButton->setStyle( new MyStyle );
    

    alt text



  • Hi,

    @SGaist yeah, it's kinda crystal ball, but at least I had no code which could provide more information than given above. ^^

    @mrjj You nailed it. That thing solved the topic in a very smooth way. thumbs.up

    Kind regards,
    Mike


Log in to reply
 

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