How to resize the QToolButton when focus is coming on that QToolButton

前端 未结 2 1328
[愿得一人]
[愿得一人] 2021-01-26 11:32

How to resize the QToolButton when focus is coming on that QToolButton. I am having 5 QToolButton, when focus is coming on 2nd QTool

相关标签:
2条回答
  • 2021-01-26 12:07

    You will have to make a custom class , subclassing QToolButton.

    class MyButton : public QToolButton
    {
        Q_OBJECT 
    
        private:
             int originalWidth, originalHeight;
             int bigWidth, bigHeight;
    };
    

    And then reimplement the focusInEvent and out.

    void focusInEvent ( QFocusEvent * event ) { 
                       resize(bigWidth,bigHeight); 
                       QToolButton::focusInEvent(event); // Don't forget to call parent focus in / out in order to make the "hover" effect work. 
    }
    
    void focusOutEvent ( QFocusEvent * event ) { 
                       resize(originalWidth,originalHeight); 
                       QToolButton::focusOutEvent(event);
    }
    

    Cheers.

    0 讨论(0)
  • 2021-01-26 12:24

    It is also possible via QSS:

    #MySecondButton:focus
    {
      width: 300px;
      height: 200px;
    }
    

    Depends on layouting and size policy it may require to set "max-width" / "max-height" / "min-width" etc, properties.

    0 讨论(0)
提交回复
热议问题