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. QDialog doesn't render properly
Forum Updated to NodeBB v4.3 + New Features

QDialog doesn't render properly

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.0k 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
    Verminoz
    wrote on last edited by
    #1

    Hello all,

    I have coded a status dialog for my project. The status dialog is supposed to be a small modal window with a status message label that appears when the application is going to do some time-consuming process. Its purpose is, quite obviously, to inform the user that the application is working on something and to block the user from doing anything on the application during that time. I coded the functions below but the problem is that the dialog appears empty while the label remains unrendered until the process is done but then the dialog is closed anyway as it's supposed to.

    Here are the functions to show and hide:
    @
    void MainWindow::showStatus(QString msg) {

    if (this->isDialogShown == true) {
        hideStatus();
    }
    
    // Create the dialog and set its settings
    this->statusDialog = new QDialog( this );
    this->statusDialog->setWindowOpacity( 0.72 );
    this->statusDialog->setWindowFlags( Qt::SplashScreen );
    this->statusDialog->setWindowModality( Qt::WindowModal );
    this->statusDialog->setFixedSize(220, 80);
    this->statusDialog->setEnabled( false );
    
    // Fix a layout for it
    this->statusDialog->setLayout( new QVBoxLayout() );
    
    // Add the label with the status message
    QLabel *label = new QLabel( this->statusDialog );
    label->setAlignment( Qt::AlignCenter );
    label->setFont( QFont("MS Shell Dlg 2", 15, QFont::Bold, true) );
    label->setText( msg );
    this->statusDialog->layout()->addWidget( label );
    
    // Show the dialog
    this->statusDialog->show();
    
    // Set flag
    this->isDialogShown = true;
    

    }

    void MainWindow::hideStatus() {

    // Close window and unset flag
    this->statusDialog->hide();
    this->isDialogShown = false;
    

    }
    @

    I use the function as such:
    @
    ...
    void MainWindow::someFunction() {
    showStatus( "Processing..." );

    someTimeConsumingFunction();
    
    hideStatus();
    

    }
    ...
    @

    How can I force the dialog to render everything before the processing starts?

    Thanks in advance!

    Ohne Muzik ware das Leben ein Irrtum.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You would probably need to call processEvents() but why don't you use a QProgressDialog ? It's purpose corresponds to your use case

      Hope it helps

      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
      0

      • Login

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