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

前端 未结 2 1329
[愿得一人]
[愿得一人] 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.

提交回复
热议问题