在多个显示器之间移动的 Qt 应用程序窗口使子对话框仅显示空空白窗口的错误 [英] Qt application windows moved between multiple monitors make child dialog showing with bug of empty blank windows only

查看:51
本文介绍了在多个显示器之间移动的 Qt 应用程序窗口使子对话框仅显示空空白窗口的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[2019 年 8 月 19 日关于此错误解决方法的更新]

[Update on 19 aug 2019 about workaround of this bug]

环境:

系统:Windows 7(在执行时也在 Windows 10 PC 上复制)

System: Windows 7 (reproduced on windows 10 PC on execution too)

QT 版本:5.11.2 和 5.13

QT version: 5.11.2 as well as 5.13

编译工具包:Qt 5.11.3 MinGw 32bits (mingw53_32)

compilation kit: Qt 5.11.3 MinGw 32bits ( mingw53_32 )

我在 Qt 应用程序中遇到 QDialog 问题.很容易重现,使用多个显示器(例如 2 个屏幕),您启动您的应用程序,然后将主窗口从一个显示器移动到另一个显示器,然后单击应用程序的按钮以显示子对话框,然后就可以了问题发生.(在我的实际情况中,并非所有 qdialog 窗口都有此错误,只有其中一些.我还无法找出根本原因.)

I encounter an issue with QDialog in Qt app. it's easy to reproduce, with multiple monitors(eg. 2 screens), you launch your application, then you move your main windows from one monitor to another one, then you click on the button of app to show a child dialog, then it this issue happens. (In my real case not all my qdialog windows get this bug, only some of them. I can't figure out root cause yet.)

有没有人知道如何解决它?

Does anyone have an idea how to workaround it?

下面的屏幕截图显示了一个简单的示例:

A simple example is shown in screenshot below:

示例主要代码:

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "Dialog1.h"
#include "Dialog2.h"


MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    mDialog1 = new Dialog1(this);
    mDialog2 = new Dialog2(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{
    mDialog1->show();
}

void MainWindow::on_pushButton_2_clicked()
{
    mDialog2->show();
}

现在我打开一个小应用程序窗口,其中只包含用于打开对话框的按钮:

Now I open a small app windows which just contain buttons to open dialogs:

-> 如果我直接单击按钮 1,则会打开一个绿色对话框,没有问题.

-> If i click on button 1 directly, a green dialog opens without problem.

现在我将这个窗口移动到我的第二个显示器,然后我点击按钮,你会看到对话框的 UI 没有显示,只是空的窗口:

Now I move this windows to my 2nd monitor, and I click on the button, you see the UI of the dialog not showing, just empty windows:

现在,如果我再次将这个空对话框移动到另一台显示器上,我最终会看到其正确的 UI 显示:

Now if I move this empty dialog to the other monitor again, I see finally its correct UI showing:

================================

===============================

经过一些测试,我发现,当对话上出现UI错误时,对其进行调整大小有助于使UI出现.

After some tests, I found that, when the UI bug happen on the dialogue, doing resize on it helps to make the UI appear.

所以我尝试了以下解决方法,只要 QT 框架仍然存在此问题.以下是解决方法代码.

So I tried below workaround as long as QT framework still present this issue. Below is the workaround code.

void MainWindow::on_pushButton_clicked()
{
    mDialog1->show();
// ****below is th working workaround, which force resize, so will trigger the paint() or sth on the UI so UI to refresh the correct display.
    mDialog1->resize(mDialog1->width() + 1, mDialog1->height());  // here need to resize to width() + N, N >=1 to make it work.
    mDialog1->resize(mDialog1->width() - 1, mDialog1->height());
...

推荐答案

如果它适用于我的 Windows 10 使用 Qt 5.13.0 MSVC 2017 而它不适用于您的 Windows 7 使用 Qt5.13,那么一定有一些差异...你用的是什么编译器?

If it works on my Windows 10 with Qt 5.13.0 MSVC 2017 and it does not on your Windows 7 with Qt5.13, then there must be some differences...What compiler are you using?

我们如何确定差异?首先,我们无法测试与您相同的程序.这就是我们要求 MRE 的原因.如果您进行 MRE,您可以隔离问题,有时您会自己找出原因.我们可以测试你的程序,也许会发现那里有一些错误.如果您不向我们提供更多信息,我们根本无法为您提供帮助.

How can we determine the differences? First of all we cannot test the same program as you have. That's why we asked for a MRE. If you make a MRE, you isolate the problem and sometimes you see the cause by yourself. We can test your program and maybe see some faults there. If you don't provide us with more information, it is simply impossible to help you.

您是对的,首先我们必须在提交错误报告之前确定这是否可重现.

You're right that first we have to determine if this is reproducible before making a bug report.

这篇关于在多个显示器之间移动的 Qt 应用程序窗口使子对话框仅显示空空白窗口的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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