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. How to make QInputDialog box modal less?
QtWS25 Last Chance

How to make QInputDialog box modal less?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 678 Views
  • 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 Offline
    M Offline
    Mr-Workalot
    wrote on last edited by
    #1

    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
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      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
      3

      • Login

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