在Qt C ++中,当鼠标悬停边框时,如何完全禁用调整窗口大小,包括调整大小图标? [英] In Qt C++, how can I fully disable resizing a window including the resize icon when the mouse hovers the border?

查看:790
本文介绍了在Qt C ++中,当鼠标悬停边框时,如何完全禁用调整窗口大小,包括调整大小图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用:
setFixedSize(size());
以停止窗口调整大小,



有没有更好的方法来禁用窗口调整大小,以避免在跨越边界时显示箭头?

解决方案

尝试这样:

  this-> statusBar() - > setSizeGripEnabled(false); 

如果这不起作用,你所需要做的就是检测什么窗口小部件正在激活 QSizeGrip 。你可以通过在你的应用程序上安装一个事件过滤器,并尝试捕捉QSizeGrip的mouseMoveEvent。



下面是您可以使用的eventFilter函数的示例:

  bool MainWindow :: eventFilter(QObject * obj,QEvent * event)
{
if(event-> type()== QEvent :: MouseMove)
{
QSizeGrip * sg = qobject_cast< QSizeGrip *>(obj);
if(sg)
qDebug()<< sg-> parentWidget();
}
return false;
}

你可能还会看到它的show事件, / p>

I used: setFixedSize(size()); to stop the window from resizing, but the resize arrows still appear when the mouse is over the border of the window.

Is there a better way to disable window resizing to avoid showing the arrows when crossing the border?

解决方案

Try something like this:

this->statusBar()->setSizeGripEnabled(false);

If this doesn't work, all you need to do is detect what widget is activating QSizeGrip. You can do this by installing an event filter on your app and try to catch the QSizeGrip's mouseMoveEvent. Then debug its parent widget.

Here's an example of the eventFilter function you could use:

bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
    if(event->type() == QEvent::MouseMove)
    {
        QSizeGrip *sg = qobject_cast<QSizeGrip*>(obj);
        if(sg)
            qDebug() << sg->parentWidget();
    }
    return false;
}

You could probably catch its show event as well, it's up to you.

这篇关于在Qt C ++中,当鼠标悬停边框时,如何完全禁用调整窗口大小,包括调整大小图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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