当焦点集中在QToolButton时如何调整QToolButton的大小 [英] How to resize the QToolButton when focus is coming on that QToolButton

查看:49
本文介绍了当焦点集中在QToolButton时如何调整QToolButton的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当焦点集中在 QToolButton 上时,如何调整 QToolButton 的大小.我有5个 QToolButton ,当焦点放在第二个 QToolButton 上时,其大小应自动增加.怎么做?

How to resize the QToolButton when focus is coming on that QToolButton. I am having 5 QToolButton, when focus is coming on 2nd QToolButton its size should automatically increase. How to so it?

推荐答案

您将必须创建一个自定义类,将QToolButton子类化.

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

class MyButton : public QToolButton
{
    Q_OBJECT 

    private:
         int originalWidth, originalHeight;
         int bigWidth, bigHeight;
};

然后重新实现focusInEvent.

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);
}

干杯.

这篇关于当焦点集中在QToolButton时如何调整QToolButton的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆