I have a problem using QSplashScreen. My application generates a log (text) file and has a menu item to let the user view a parsed display of this file in a table in a dialog. Since the file can be up to 500k, it takes a while to parse so I use a QSplashScreen to distract the user during the parsing (sometimes more than 5000 lines). The QSplashScreen is semi-transparent and displays a message indicating how many lines of the log file have been parsed.

I know this is not normal usage of a QSplashScreen but it works fine except for the following.

My problem is that if a user repeatedly clicks outside the QSplashScreen, in the main window title bar for example, after reading between 700 and 1200 lines of the > 5000 line file:
  • the message in the QSplashScreen freezes at a line number (but the file continues to be parsed)
  • the main window MAY be drawn over the QSplashScreen
  • the client area of the main window goes away (repainted in white)
  • when the file is finished being read, the dialog displays the log file contents correctly but the QSplashScreen is drawn on top and never goes away until the application closes

While all of the results above are irritating, the worst is that the splash screen never goes away (even after the dialog is gone).

I have tried trapping (and ignoring) the mousePressEvents in both the main window and the dialog but the mousePressEvent() function never gets the mouse events while the QSplashScreen is active. This is not surprising since it appears that the QSplashScreen has focus.

I noticed that a mouse press should cause the splash screen to become hidden, but in this case it doesn't happen.

BTW, I'm using 4.2.2 with VS2005.

Any suggestions for fixing this weird mouse click problem?

Qt Code:
  1. // From the class definition...
  2. QTableWidget* m_logTable;
  3. MainWin* m_pMainWin;
  4. QSplashScreen* m_pSplash;
  5. QFile m_logFile;
  6.  
  7. // Show Log file dialog ctor
  8. ShowLog::ShowLog( QWidget *pParent ) : QDialog( pParent )
  9. {
  10. m_pMainWin = static_cast<MainWin*>( pParent );
  11. QDir::setCurrent( QDir::currentPath() );
  12.  
  13. m_logFile.setFileName( LOG_FILENAME );
  14.  
  15. QIODevice::OpenMode nOpenMode = QIODevice::ReadOnly | QIODevice::Text;
  16.  
  17. if ( !m_logFile.exists() )
  18. reject();
  19.  
  20. if ( !m_logFile.open( nOpenMode ) )
  21. reject();
  22.  
  23. QPixmap pMap( SHOWLOG_SPLASH_IMG );
  24.  
  25. // Make the corners fully transparent (rounded-corner bitmap)
  26. if ( !pMap.mask().isNull() )
  27. {
  28. QImage img( SHOWLOG_SPLASH_IMG );
  29. if ( img.hasAlphaChannel() )
  30. pMap.setMask( QBitmap::fromImage( img.createAlphaMask() ) );
  31. else
  32. pMap.setMask( QBitmap::fromImage( img.createHeuristicMask() ) );
  33. }
  34.  
  35. ui.setupUi( this );
  36.  
  37. QPalette palette = ui.centralWidget->palette();
  38. palette.setColor( ui.centralWidget->backgroundRole(), COLOR_ManageBkg );
  39. ui.centralWidget->setPalette( palette );
  40.  
  41. m_logTable = new QTableWidget( 0, 4, this );
  42.  
  43. // Layout the Show Logfile dialog
  44. .
  45. .
  46. .
  47. // Initialize the text stream
  48. QTextStream logStream( &m_logFile );
  49. QString sLine, sSrc, sType, sTime, sMsg;
  50. QString sMsgText( " Reading %1: line %2" );
  51. Qt::ItemFlags flags;
  52. int start, end, nRow = 0;
  53.  
  54. // Skip the header
  55. while ( (sLine = logStream.readLine())[0] == '*' );
  56.  
  57. // Set up the splash screen
  58. m_pSplash = new QSplashScreen( pParent, pMap );
  59. m_pSplash->setWindowOpacity( 0.8 ); // make the image semi-transparent
  60. palette = m_pSplash->palette();
  61. palette.setBrush( QPalette::Window, QBrush( pMap ) );
  62. m_pSplash->setPalette( palette );
  63. m_pSplash->setFixedSize( pMap.size() );
  64. m_pSplash->setMask( pMap.mask() );
  65. QFont font = m_pSplash->font();
  66. font.setBold( true );
  67. m_pSplash->setFont( font ); // Set the m_pSplash font to bold
  68.  
  69. // Center the splash screen in the main application window
  70. m_pSplash->move( m_pMainWin->pos().x() +
  71. (m_pMainWin->frameGeometry().width() / 2) -
  72. (m_pSplash->frameGeometry().width() / 2),
  73. m_pMainWin->pos().y() +
  74. (m_pMainWin->frameGeometry().height() / 2) -
  75. (m_pSplash->frameGeometry().height() / 2) );
  76. m_pSplash->show();
  77.  
  78. // Load the text
  79. while ( !logStream.atEnd() || !sLine.isEmpty() )
  80. {
  81. if ( sLine.isEmpty() ) // skip any empty lines
  82. {
  83. sLine = logStream.readLine();
  84. continue;
  85. }
  86.  
  87. // Parse the Source
  88. .
  89. .
  90. .
  91. // Fill a table row
  92. m_logTable->insertRow( nRow );
  93. .
  94. .
  95. .
  96. nRow++;
  97. sLine = logStream.readLine();
  98.  
  99. // Incremental splash message
  100. m_pSplash->showMessage( sMsgText.arg( LOG_FILENAME ).arg( nRow ),
  101. nMsgAlignment, textColor );
  102. }
  103.  
  104. // Close the QFile
  105. if ( m_logFile.isOpen() )
  106. m_logFile.close();
  107.  
  108. // Set sort indicator in column headers
  109. m_logTable->horizontalHeader()->setSortIndicatorShown( true );
  110. m_logTable->setSortingEnabled( true );
  111.  
  112. m_pSplash->finish( this );
  113.  
  114. }
To copy to clipboard, switch view to plain text mode