在MainWindow中全屏显示QDialog有时只能工作 [英] Fullscreen for QDialog from within MainWindow only working sometimes

查看:202
本文介绍了在MainWindow中全屏显示QDialog有时只能工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(在Qt 4.8和Ubuntu 12.10上使用C ++进行测试)

(Testing with C++ on Qt 4.8 and Ubuntu 12.10 unity)

我有一个显示QDialog的主窗口.当我将对话"窗口全屏显示时,即使它似乎是一个适当的窗口,它也似乎并不总是能正常工作. 这意味着该窗口可以全屏显示,尽管有时只是这样.

I've got a main window which displays a QDialog. When I put the Dialog window full-screen it does not seem to always work even though it seems to be a proper window. Meaning, the window can appear full-screen, though only sometimes.

有人知道吗?我知道Qt指出它可能不适用于所有X环境,但不是那么糟糕,不是吗?

Anyone got an idea? I know Qt states it might not work for all X environments, but it can't be that bad, can it?

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QDialog* d = new QDialog();
    d->setModal(false);
    d->show();       
    qDebug() << d->isWindow();

    // works most of the times, though not always:
    // d->showFullScreen();

    // sometimes works, sometimes it doesn't:
    QTimer::singleShot(2000, d, SLOT(showFullScreen()));
}

推荐答案

此处的stackoverflow上的DomTomCat显示了一种检测Ubuntu的方法,而QDialog问题与Metacity(Ubuntu的默认窗口管理器)中的错误有关.

DomTomCat here at stackoverflow showed a way to detect Ubuntu and the QDialog problem is related to a bug in Metacity (Ubuntu's default window manager).

Metacity不能以相同的方式管理对话框和主窗口,因此必须欺骗使其认为QDialog是普通窗口.为了使用QDialog类这样做,必须更改其窗口标志.

Metacity doesn't manage the same way dialogs and main windows and it has to be tricked making it think that a QDialog is a normal window. In order to do so using QDialog class it's window flags have to be changed.

您无需检测DomTomCat所说的所有步骤,而是可以检测到会话,然后只需

Instead of doing all the steps DomTomCat says, you can detect the session and then just

//example inside the QDialog
this->setWindowFlags(Qt::Window);
this->showFullScreen();

该错误已在之前报告(并忽略),但据我所知,这是第一个简单的解决方法.

The bug was reported (and ignored) before but as far as I know this is the first simple workaround.

https://bugreports.qt.io/browse/QTBUG-16034

https://git.gnome.org /browse/metacity/tree/src/core/window.c#n6326

Ubuntu也可以使用compiz.可以在以下位置看到

Ubuntu can also use compiz. This can be seen at:

grep DefaultProvider-windowmanager /usr/share/gnome-session/sessions/*

最诚挚的问候,

Iker De Echaniz.

Iker De Echaniz.

这篇关于在MainWindow中全屏显示QDialog有时只能工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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