0

I have a QWidget which shows a QMessageBox on the show event. I have overridden the showEvent function for the QWidget. The problem is, that the messagebox is displayed first, and the rest of the widget is displayed later. How do I resolve this problem?

void InstallScreen::showEvent( QShowEvent *s )
{ 
   QMessageBox::about( m_main, "One Click Installer", 
          QString( "The following repositories will be added \n %1" ).arg( repoList ) ); 
   QMessageBox::about( m_main, "One Click Installer", 
          QString( "The following packages will be installed \n %1" ).arg( packList ) ); 
} 
demonplus
  • 5,613
  • 12
  • 49
  • 68
saurabhsood91
  • 449
  • 1
  • 5
  • 21
  • void InstallScreen::showEvent( QShowEvent *s ) { QMessageBox::about( this, "One Click Installer", QString( "The following repositories will be added \n %1" ).arg( "Repo1" ) ); } – saurabhsood91 Jul 19 '12 at 06:37
  • FYI: Editing posts is way better than adding code in a comment. Can't possibly read that. :) – Macke Jul 20 '12 at 16:59

1 Answers1

2

Use a delayed call to show the widget, for instance by putting the widget show code in a slot and calling it with QTimer::singleShot with a delay of 0 secs.

This will allow the showEvent to process fully and schedule any redraw events on the mainloop before you show your widget. This will make the widget & messagebox to be shown/drawn/repainted independently of each other.

protected:
void MyWidget::showEvent(...) {
     ...
     QTimer::singleShot(0, this, SLOT(showMessageBox());
}

private slots:
void MyWidget::showMessageBox() {
     QMessageBox::information(...); // or whatever
}

If you need some extra margin (for whatever reason), set the timer delay to 50 or 100 ms.

Macke
  • 24,812
  • 7
  • 82
  • 118