WSL vs Native Ubuntu Modeless Dialog
-
Hello,
I"m using WSL2 with gui support and Ubuntu 20.04.4 LTS distr + qt 5.15.5
I have an app building/running both on windows/native ubuntu and wsl.
However on WSL, i have a small diff in behavior - upon opening a QDialog in modeless mode, which should allow me to provide input into parent window, on WSL this somehow does not work and until I close this dialog, no input would be allowed on the parent window.I tried to open a QDialog with nullptr for the parent and in that case it works, but that's not exactly what i need.
Are there any suggestions on what else i can try?
Would there be any insight into what might be wrong?
I tried both wayland and xcb. I guess i need to create a smallish reproducerVK
-
Hi,
A dialog with a parent is automatically modal to its parent so it looks like the behaviour on WSL is the correct one i.e. you can only interact with the dialog until you accept or dismiss it.
Can you explain your use case ?
-
Hello,
Here is the reproducer
#include <iostream> #include "QString" #include "QApplication" #include "QLabel" #include "QMainWindow" #include "QPushButton" #include "QDialog" #include "QTextEdit" #include "QWindow" // NOTE: this should not be done in prod app QMainWindow* g_w = nullptr; // NOTE: this stuff should not be used in real app // TODO: does Qt manager ownership of closed windows/dialogs as well? void on_clicked() { std::cout << "opening a new dialog!" << std::endl; // craete a dialog // NOTE: neither adding Qt::WindowStaysOnTopHint nor Qt::X11BypassWindowManagerHint // seems to help auto d = new QDialog{g_w}; d->resize(240, 160); // add a dummy label auto l = new QLabel{d}; l->setText("This is a newly opened dialog"); // force modeless window! d->setWindowModality(Qt::NonModal); d->setModal(false); d->show(); } void on_clicked_open_qwindow() { std::cout << "open a new window!" << std::endl; // craete a dialog auto d = new QMainWindow{g_w}; d->resize(240, 160); // add a dummy label auto l = new QLabel{d}; l->setText("This is a newly opened window"); // force modeless window! d->setWindowModality(Qt::NonModal); d->show(); } int main(int argc, char** argv) { std::cout << "hello world!" << std::endl; QApplication app{argc, argv}; // setup the layout QMainWindow w{nullptr}; w.resize(640, 480); g_w = &w; QPushButton button{"Open Dialog", &w}; if (argc == 1) { QObject::connect( &button, &QPushButton::clicked, on_clicked ); } else { QObject::connect( &button, &QPushButton::clicked, on_clicked_open_qwindow ); } QTextEdit te{&w}; te.setText("Provide Some Input: "); te.setAlignment(Qt::AlignCenter); te.setGeometry(400, 200, 100, 60); // show the window w.show(); // start the event loop return app.exec(); }
with some cmake ( I use qt 5.15.5 from conan central)
cmake_minimum_required(VERSION 3.20) project(test LANGUAGES C CXX) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTORCC ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED True) find_package(Qt5 REQUIRED) add_executable(qt__qdialog_reproducer main.cpp) target_link_libraries(qt__qdialog_reproducer Qt5::Qt5)
As it can be seen - i explicitly set the modality of the QDialog to be nonModal, even twice...
The usecase is to open up a dialog (with a parent) and still allow to provide input to a parent window.What i found is that if i replace line 31 to be
auto d = new QDialog{g_w, Qt::Window};
then I do get the behavior i want with 1 smallish exception.
The opened up dialog goes behind the main window when i start providing input to the main window... on windows that was not the case...
I tried adding flags likeQt::WindowStaysOnTopHint
Qt::X11BypassWindowManagerHint
but no effect - actually adding them with OR made things even worse...any help would be very appreciated!
VK