QT中使用Event Filter监听按钮事件,Release后按钮不见

问题RT,在程序中我使用了QT的监听事件,监听鼠标的位置,如果鼠标在按钮上就改变按钮的ICON,但是在Release版本中(Debug版本没问题),这些被监听的按钮都看不见了,于是开始了寻找答案的道路。

闲话少叙,直接上码:

void MainHomeForm::init()
{
    //为按钮注册事件
    ui->SystemSetButton->installEventFilter(this);
    ui->ZoneSetButton->installEventFilter(this);
}
//系统监听器监听按钮对象
bool MainHomeForm::eventFilter(QObject *target, QEvent *e)
{
    if(target == ui->SystemSetButton)
    {
        if(e->type() == QEvent::Enter)
        {
            ui->SystemSetButton->resize(163,91);
            ui->SystemSetButton->setIcon(QIcon(":/new/prefix1/back/系统设置2.png"));
        }
        else if(e->type() == QEvent::Leave)
        {
            ui->SystemSetButton->resize(115,60);
            ui->SystemSetButton->setIcon(QIcon(":/new/prefix1/back/系统设置.png"));
        }
    }
    else if(target == ui->ZoneSetButton)
    {
        if(e->type() == QEvent::Enter)
        {
            ui->ZoneSetButton->resize(163,91);
            ui->ZoneSetButton->setIcon(QIcon(":/new/prefix1/back/区域控制2.png"));
        }
        else if(e->type() == QEvent::Leave)
        {
            ui->ZoneSetButton->resize(115,60);
            ui->ZoneSetButton->setIcon(QIcon(":/new/prefix1/back/区域控制.png"));
        }
    }
}

想法一:显示不了按钮图片,应该是图片的路径问题吧,于是使用在Release路径下添加imageformats文件夹,还是不行

想法二:我发现按钮都点不了了,那应该不是图片的路径问题了,直接出在按钮上,果断注释了为按钮注册事件的两句话,发现Release后按钮显示了

发现程序中我忽略了这么一个Warning:


哦,之前一直忽略了,原来是因为eventFilter这个函数我没给返回值,那我给一个好了

返回FALSE吧,发现按钮还是不见

返回TRUE吧,发现按钮可见了

预测:应该是返回值影响了按钮是否可见吧


最终解决办法:EventFilter要返回True哦

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值