Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Unsolved How to make QInputDialog box modal less?

    General and Desktop
    2
    2
    483
    Loading More Posts
    • 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.
    • M
      Mr-Workalot last edited by

      i am using multiple QInput Dialog boxes in my UI, using the syntax like

      QString s = QInputDialog::getText(this,"Sleep Command ","Enter the number of seconds" );
      
      

      but when ever these Input dialog boxes pops up, the mainwindow becomes unresponsive, so how do i make all the QInputDialog boxes "modal less " and the mainwindow always stays responsive ??

      1 Reply Last reply Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by mrjj

        Hi
        When you call QInputDialog::
        you are calling a static function that shows the dialog for you.

        If you want to use them non modal, then you must create and show the dialog your self and handle reading the data.

        https://forum.qt.io/topic/14761/non-blocking-dialogbox-nonmodal-required-for-statusmessages

        Hmm that was quite old link :)

        In a newer world, lambdas make this more compact.

        QInputDialog *d = new QInputDialog;
        
            connect( d, &QDialog::accepted, this, [d]() {
                auto text = d->textValue();  // get text        
                d->deleteLater();// clean up
            });
        
            d->show(); 
        
        note: we are only handling accepted so if cancel or esc is used then we leak!
        You might be able to use d->setAttribute(Qt::WA_DeleteOnClose);
        Or simply keep one instance around for full life time of app and simply hide or show as needed.
        
        

        But you change your app's logic a bit as you won't get the text now in place as it no longer blocks the main thread and
        will continue to execute while showing the dialog.
        So the text from dialog will come at later point in time than your current code.
        Just so you are aware of it.

        1 Reply Last reply Reply Quote 3
        • First post
          Last post