Results 1 to 11 of 11

Thread: Update to 4.4.2 - Now I Have A Transparent Dialog

  1. #1
    Join Date
    Aug 2006
    Location
    Madison, WI USA
    Posts
    153
    Thanks
    35
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question Update to 4.4.2 - Now I Have A Transparent Dialog

    I've recently updated my Qt installation from 4.3.4 to 4.4.2. I have a simple dialog which is to display a 1 line message while some time-consuming operation is happening. When the operation has finished the dialog closes.

    Using 4.3.4 this was displaying as expected but since my switch to 4.4.2 the dialog body has become transparent (no background color, no text).

    Based on my years of programming experience, I assume that my code has worked by accident in 4.3.4 and 4.4.2 has uncovered a defect. Can anyone see what is going wrong here?

    I've attached a bitmap of what I'm seeing.

    Qt Code:
    1. class GenericWaitDlg : public QDialog
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. GenericWaitDlg( QWidget *pParent );
    7. void Initialize( QString sTitle, QString sMsg );
    8.  
    9. private:
    10. Ui::GenericDlgClass ui;
    11. QWidget* m_pParent;
    12. MainWin* m_pMainWin;
    13.  
    14. };
    15.  
    16.  
    17. GenericWaitDlg::GenericWaitDlg( QWidget* pParent )
    18. : QDialog( pParent )
    19. , m_pParent( pParent )
    20. , m_pMainWin( reinterpret_cast<MainWin*>(
    21. reinterpret_cast<NetConfigDlg*>( pParent )->m_pMainWin ) ) {}
    22.  
    23.  
    24. void GenericWaitDlg::Initialize( QString sTitle, QString sMsg )
    25. {
    26. // Remove the system menu, close button and context help button
    27. setWindowFlags( windowFlags() ^
    28. (Qt::WindowSystemMenuHint | Qt::WindowContextHelpButtonHint) );
    29.  
    30. ui.setupUi( this );
    31.  
    32. // Create Title and text strings
    33. setWindowTitle( sTitle );
    34. QLabel* sText = new QLabel( sMsg, this );
    35.  
    36. // Get the label size and use to fix dialog width
    37. QSize labelSize = sText->sizeHint().expandedTo( sText->sizeHint() );
    38. labelSize.setWidth( labelSize.width() + 120 );
    39.  
    40. // Layout label
    41. QHBoxLayout* hBox = new QHBoxLayout();
    42. hBox->addWidget( sText, 0, Qt::AlignHCenter );
    43.  
    44. // Main layout
    45. QVBoxLayout* vbox = new QVBoxLayout( this );
    46. vbox->addSpacing( 10 );
    47. vbox->addLayout( hBox, Qt::AlignRight );
    48. vbox->addSpacing( 15 );
    49. setLayout( vbox );
    50.  
    51. resize( labelSize.width(), labelSize.height() * 8 );
    52.  
    53. // Center the dialog in the parent window
    54. move( m_pParent->pos().x() +
    55. (m_pParent->frameGeometry().width() / 2) - (frameGeometry().width() / 2),
    56. m_pParent->pos().y() +
    57. (m_pParent->frameGeometry().height() / 2) - (frameGeometry().height() / 2) );
    58. }
    59.  
    60. // Instantiate, initialize and show the dialog
    61. GenericWaitDlg dlg( m_parent );
    62. dlg.Initialize( DLG_TITLE, DLG_MSG );
    63. dlg.show();
    64. // Do some work here...
    65. dlg.done( 0 );
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Update to 4.4.2 - Now I Have A Transparent Dialog

    i) the code does not produce a transparent dialog here (Qt 4.4.1)
    ii) might be an error in your .ui file (we haven't got that)
    iii) the xor is a bit fishy. idion for removing bits is
    Qt Code:
    1. x &= ~(bits_to_remove)
    To copy to clipboard, switch view to plain text mode 
    iv) why cast to reinterpret_cast<NetConfigDlg*>( pParent ) ? Just pass a NetConfigDlg in the constructor instead of the QWidget!
    v) the other cast: why cast an x to an x? a bit pointless ;-) try to save on those casts!

    HTH

  3. #3
    Join Date
    Aug 2006
    Location
    Madison, WI USA
    Posts
    153
    Thanks
    35
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Update to 4.4.2 - Now I Have A Transparent Dialog

    I have distilled this down to a minimal app. Using 4.4.2, the dialog interior is transparent while the identical code using 4.3.4 contains a background and text.

    .ui File
    Qt Code:
    1. <UI version="4.0" stdSetDef="1" >
    2. <class>GenericDlgClass</class>
    3. <widget class="QDialog" name="GenericDlgClass" >
    4. <property name="objectName" >
    5. <cstring>GenericDlgClass</cstring>
    6. </property>
    7. <property name="geometry" >
    8. <rect>
    9. <x>0</x>
    10. <y>0</y>
    11. <width>300</width>
    12. <height>500</height>
    13. </rect>
    14. </property>
    15. </widget>
    16. <layoutDefault spacing="6" margin="11" />
    17. <pixmapfunction></pixmapfunction>
    18. <resources/>
    19. <connections/>
    20. </UI>
    To copy to clipboard, switch view to plain text mode 

    Source Files
    Qt Code:
    1. #include <QDialog>
    2. #include "ui_GenericDlg.h"
    3.  
    4. class GenericWaitDlg : public QDialog
    5. {
    6. Q_OBJECT
    7.  
    8. public:
    9. GenericWaitDlg( QString sTitle, QString sMsg, QWidget* pParent = 0 );
    10.  
    11. private:
    12. Ui::GenericDlgClass ui;
    13. };
    14.  
    15.  
    16. #include <QLabel>
    17. #include "GenericWaitDlgTest.h"
    18.  
    19. GenericWaitDlg::GenericWaitDlg( QString sTitle, QString sMsg, QWidget* pParent )
    20. : QDialog( pParent )
    21. {
    22. ui.setupUi( this );
    23. setWindowTitle( sTitle );
    24.  
    25. // Get the label size and use to fix dialog width
    26. QLabel* sText = new QLabel( sMsg, this );
    27. QSize labelSize = sText->sizeHint().expandedTo( sText->sizeHint() );
    28. labelSize.setWidth( labelSize.width() + 120 );
    29. resize( labelSize.width(), labelSize.height() * 8 );
    30. }
    31.  
    32.  
    33. #include <QApplication>
    34. #include "GenericWaitDlgTest.h"
    35.  
    36. int main( int argc, char *argv[] )
    37. {
    38. QApplication app( argc, argv );
    39.  
    40. GenericWaitDlg dlg( "GenericWaitDialog", "GenericWait Dialog message..." );
    41. dlg.show();
    42. for ( int i = 0; i < 0x7FFFFFFF; i++ ); // Simulate some work...
    43. dlg.done( 0 );
    44.  
    45. return 0;
    46. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Update to 4.4.2 - Now I Have A Transparent Dialog

    You cannot block the event loop with a busy loop (in fact, in the minimal test case you don't run an event loop at all). The application has no chance to deliver paint events, thus nothing gets painted.
    J-P Nurmi

  5. #5
    Join Date
    Aug 2006
    Location
    Madison, WI USA
    Posts
    153
    Thanks
    35
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Update to 4.4.2 - Now I Have A Transparent Dialog

    Quote Originally Posted by jpn View Post
    You cannot block the event loop with a busy loop (in fact, in the minimal test case you don't run an event loop at all). The application has no chance to deliver paint events, thus nothing gets painted.
    In that case this example should perform the same using both versions of Qt, no?

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Update to 4.4.2 - Now I Have A Transparent Dialog

    Quote Originally Posted by mclark View Post
    In that case this example should perform the same using both versions of Qt, no?
    Perhaps 4.3.4 creates the native window handle upon show(), whereas 4.4.0 probably doesn't do it at that point yet. It doesn't mean that the minimal test app works with either version. You MUST let the application process its events in order to make the dialog responsive.
    Qt Code:
    1. for ( int i = 0; i < 0x7FFFFFFF; i++ ) // Simulate some work...
    2. app.processEvents();
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  7. The following user says thank you to jpn for this useful post:

    mclark (6th October 2008)

  8. #7
    Join Date
    Aug 2006
    Location
    Madison, WI USA
    Posts
    153
    Thanks
    35
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Update to 4.4.2 - Now I Have A Transparent Dialog

    Quote Originally Posted by jpn View Post
    You MUST let the application process its events in order to make the dialog responsive.
    Ahhhh.... Now I see what you mean about the minimal test app.

    So, what would you recommend for a solution for the real app?

    I have a QDialog which needs to make a library call that may take 3-7 seconds (on average) to complete. I want to display something to let a user know that processing is happing (the app is NOT hung). I was using the GenericWaitDlg class described above.

  9. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Update to 4.4.2 - Now I Have A Transparent Dialog

    Quote Originally Posted by mclark View Post
    So, what would you recommend for a solution for the real app?

    I have a QDialog which needs to make a library call that may take 3-7 seconds (on average) to complete. I want to display something to let a user know that processing is happing (the app is NOT hung). I was using the GenericWaitDlg class described above.
    What kind of library call is that? Unless there is a way to split the task into smaller chunks, I'm afraid you have to process it in a worker thread and deliver results to the main GUI thread for example by using queued signals.
    J-P Nurmi

  10. #9
    Join Date
    Aug 2006
    Location
    Madison, WI USA
    Posts
    153
    Thanks
    35
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Update to 4.4.2 - Now I Have A Transparent Dialog

    Quote Originally Posted by jpn View Post
    What kind of library call is that?
    The call is to a library I have no control over (not a Qt call). I was hoping there might be a solution other than using a worker thread.

    Does this sound reasonable:
    1. create my GenericWaitDlg
    2. create a worker thread
    3. connect a slot (closeGenericWaitDlg()) to the finished() signal of the thread
    4. in the run() method of the thread, make my library call
    5. when the library call is finished the thread should shutdown
    6. in the closeGenericWaitDlg() method call dlg.done(0) to close the wait dialog

  11. #10
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Update to 4.4.2 - Now I Have A Transparent Dialog

    Yes, sounds reasonable. Just remember not to touch GUI in the worker thread.
    J-P Nurmi

  12. The following user says thank you to jpn for this useful post:

    mclark (6th October 2008)

  13. #11
    Join Date
    Aug 2006
    Location
    Madison, WI USA
    Posts
    153
    Thanks
    35
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Update to 4.4.2 - Now I Have A Transparent Dialog

    Thanks for your help, jpn. It is much appreciated!

Similar Threads

  1. Update to 4.4.2 generates new warnings
    By mclark in forum Qt Programming
    Replies: 1
    Last Post: 19th September 2008, 19:59

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.