如何在Qt中为QMainWindow切换“始终在顶部”,而不会导致闪烁或闪烁? [英] How do I toggle 'always on top' for a QMainWindow in Qt without causing a flicker or a flash?

查看:620
本文介绍了如何在Qt中为QMainWindow切换“始终在顶部”,而不会导致闪烁或闪烁?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  void MainWindow :: on_actionAlways_on_Top_triggered(bool checked)
{
Qt :: WindowFlags flags = this-> windowFlags();
if(checked)
{
this-> setWindowFlags(flags | Qt :: CustomizeWindowHint | Qt :: WindowStaysOnTopHint);
this-> show();
}
else
{
this-> setWindowFlags(flags ^(Qt :: CustomizeWindowHint | Qt :: WindowStaysOnTopHint));
this-> show();上面的解决方案是可行的,但是因为setWindowFlags隐藏了窗口,所以我们可以使用下面的代码:它需要重新显示,当然不看起来很优雅。那么如何在没有闪烁副作用的情况下切换QMainWindow的始终在顶部?

解决方案

诺基亚不说

无法进行更改到窗口标志一旦窗口已经创建而不引起闪烁。闪烁是不可避免的,因为窗口需要重新创建。

但有时,如果你被困在一个像这样丑陋的效果,你可以有意拖出它



可能弹出一个不在窗口中的进度条,说调整窗口属性!使窗口消失存在然后重新进入,并关闭进度条弹出窗口。


void MainWindow::on_actionAlways_on_Top_triggered(bool checked)
{
    Qt::WindowFlags flags = this->windowFlags();
    if (checked)
    {
        this->setWindowFlags(flags | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint);
        this->show();
    }
    else
    {
        this->setWindowFlags(flags ^ (Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint));
        this->show();
    }
}

The above solution works but because setWindowFlags hides the window, it needs to be re-shown and of course that doesn't look very elegant. So how do I toggle "always on top" for a QMainWindow without that "flashing" side effect?

解决方案

Nokia says no:

It is not possible to make changes to the window flags once the window has been created without causing flicker. Flicker is unavoidable since the window needs to be recreated.

But sometimes if you're stuck with a flashing effect that's kind of ugly like this, you can intentionally drag it out to make it seem like something "cool" just happened.

Maybe pop up a little progress bar that's not in the window, say "Adjusting Window Properties!"...fade the window out of existence and then back in, and close the progress bar popup.

这篇关于如何在Qt中为QMainWindow切换“始终在顶部”,而不会导致闪烁或闪烁?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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