Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Modify hit box of QRadioButton (SE_RadioButtonClickRect)
Qt 6.11 is out! See what's new in the release blog

Modify hit box of QRadioButton (SE_RadioButtonClickRect)

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 1.7k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lachrymology
    wrote on last edited by Lachrymology
    #1

    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

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #3

        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

        1 Reply Last reply
        2
        • L Offline
          L Offline
          Lachrymology
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved