Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. WSL vs Native Ubuntu Modeless Dialog
Forum Updated to NodeBB v4.3 + New Features

WSL vs Native Ubuntu Modeless Dialog

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 246 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Viktor Khristenko
    wrote on 22 Sept 2022, 14:45 last edited by
    #1

    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 reproducer

    VK

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 22 Sept 2022, 19:17 last edited by
      #2

      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 ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • V Offline
        V Offline
        Viktor Khristenko
        wrote on 23 Sept 2022, 15:03 last edited by
        #3

        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 like Qt::WindowStaysOnTopHint Qt::X11BypassWindowManagerHint but no effect - actually adding them with OR made things even worse...

        any help would be very appreciated!

        VK

        1 Reply Last reply
        0

        1/3

        22 Sept 2022, 14:45

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved