Qt application windows moved between multiple monitors make child dialog showing with bug of empty blank windows only

你离开我真会死。 提交于 2021-02-10 06:36:50

问题


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

environements:

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

QT version: 5.11.2 as well as 5.13

compilation kit: Qt 5.11.3 MinGw 32bits ( mingw53_32 )

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:

Main Code of the example:

#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:

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

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:

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

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

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

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());
...

回答1:


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?

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.




回答2:


Let's do it the other way around. Can you use my test program on your system? (it is complete with pro file, ui files, h and cpp files, so you will not need to do a lot of work to test it...) It can be used to file a bug report if needed = double reward.

PS: you're supposed to provide an example like that to attract people to test with minimal effort.

Here is the example I tested: testDoubleMonitor




回答3:


I faced a similar issue wherein I would see “blanked out dialog boxes” in my application on multi monitor PC’s Specifically if they would be displayed using the blocking exec() call. Changing this to use the non-blocking show() and handling the response in slots for accepted () and rejected() fixed it. Version of Qt used 5.12.4 LTS




回答4:


This is caused by a QT-BUG, have to be aware of is please ignore the discription:

Bug in Windows 10 is first introduced in 5.12.4, Previous versions (<5.12.4) work as intended.

I tested with Qt5.12.3+Win10 also have this problem described in my another question, and after updated to Qt5.12.10, QDialog worked well.



来源:https://stackoverflow.com/questions/57392069/qt-application-windows-moved-between-multiple-monitors-make-child-dialog-showing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!