Results 1 to 13 of 13

Thread: Problems updating a dialog

  1. #1
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Problems updating a dialog

    Hi all, I have a dialog window that contains 2 widgets inside. When this 2 widgets need to update their contents, they show a progress dialog. I've reimplemented the showEvent of the widgets to check if they need to update their contents. The problem is that in the first show, when the dialog is opened (executed in this case), the progress dialog is shown before the dialog window is shown and looks bad. What I want in this case is: 1) show (paint) the dialog window 2) show the progress dialog while both widgets are updating. I've tried to reimplement the showEvent method of the dialog and call 'repaint' and 'processEvents' but it doesn't works. Any suggestions will be really appreciated...

    Thanks.
    Last edited by SkripT; 30th March 2006 at 12:25.

  2. #2
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Problems updating a dialog

    You code can be helpfull, but i if i have good understanding of your problem i think that you must use threads for showing progress dialog
    a life without programming is like an empty bottle

  3. #3
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problems updating a dialog

    Quote Originally Posted by zlatko
    ... i think that you must use threads for showing progress dialog
    Sorry zlatko, why do you think that I must use threads? I don't see any relationship between what I want to do and the use of threads... Maybe you mean that I must use threads to update the widgets?
    Last edited by SkripT; 30th March 2006 at 11:14.

  4. #4
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Problems updating a dialog

    Ok show you available now code maiby problem will be easier
    a life without programming is like an empty bottle

  5. #5
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problems updating a dialog

    That's the code for both widgets of the dialog:

    This method is to update the contents of the widget:
    Qt Code:
    1. void ImageWindow::updateWindow()
    2. {
    3. if (fotoValida && taulaValida) return;
    4. QProgressDialog progres("Carregant imatge i actualitzant informació...", 0, 0, 3, this);
    5. progres.setMinimumDuration(0);
    6.  
    7. progres.setValue(1);
    8.  
    9. if (!fotoValida)
    10. {
    11. butoEditorFoto -> setEnabled(foto -> fixaFoto(QImage(pathFoto)/*.scaled(tamIniAreaFoto, Qt::KeepAspectRatio)*/));
    12. fotoValida = true;
    13. }
    14.  
    15. progres.setValue(2);
    16.  
    17. if(!taulaValida)
    18. {
    19. omplirParamsFitxer();
    20. omplirParamsRetallat();
    21. taulaValida = true;
    22. }
    23.  
    24. progres.setValue(3);
    25. }
    To copy to clipboard, switch view to plain text mode 

    That's how I reimplement the showEvent:
    Qt Code:
    1. void ImageWindow::showEvent(QShowEvent *event)
    2. {
    3. if (!event -> spontaneous())
    4. updateWindow();
    5. }
    To copy to clipboard, switch view to plain text mode 

    At the beginning "fotoValida" and "taulaValida" are false, so in the first time that the widgets are shown they update their contents. The problem is that this first update is before the dialog window is shown (painted on screen). That's the real problem detailed in my first post.
    Last edited by SkripT; 30th March 2006 at 12:23.

  6. #6
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problems updating a dialog

    This is how I've tried it the last time:

    This is the reimplementation of the showEvent method for the dialog that I used to to the test:
    Qt Code:
    1. void ImageWindowsDialog::showEvent(QShowEvent *event)
    2. {
    3. if (!event -> spontaneous())
    4. {
    5. finestraFoto -> hide();
    6. finestraFotoOriginal -> hide();
    7.  
    8. show();
    9.  
    10. repaint();
    11. qApp -> processEvents();
    12. finestraFoto -> show();
    13. finestraFotoOriginal -> show();
    14.  
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 

    "finestraFoto" and "finestraFotoOriginal" are the widgets of class "ImageWindow" that show the progress dialog.

    Anybody could explain me why the progress dialogs continue appearing before the dialog windows is drawn???

  7. #7
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problems updating a dialog

    Could someone suggest me a way to know when the dialog is shown (painted) for the first time? I've tried emiting a signal in the showEvent but it doen't works. What I want is delay the update of the widgets (showing the progress dialog while doing it) that contains the dialog window until it is drawn

  8. #8
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problems updating a dialog

    Hi again, let's see if this time I have more luck I attach three images showing the steps that I want to follow/obtain in sequence when the dialog window is executed:

    1) First step (image 1): show the dialog window with the contents of both image widgets "empty".
    2)Second Step (image 2): show the progress dialog while both widgets are updating their contents. It will show two progress dialogs one after the other for each image widget.
    3)Third Step (image 3): the update process is finished.

    The problem is that it's impossible to begin with the first step: it always starts with the second step, without showing the "empty dialog" on background. I want to know some method to first show the dialog and then update its contents.
    Attached Images Attached Images
    Last edited by SkripT; 31st March 2006 at 15:15.

  9. #9
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problems updating a dialog

    Nobody could suggest me something?

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problems updating a dialog

    Try adding a single shot timer with 0 timeout in showEvent:
    Qt Code:
    1. void ImageWindowsDialog::showEvent( QShowEvent * event ) {
    2. QDialog::showEvent( event );
    3. QTimer::singleShot( 0, this, SLOT( startUpdate() ) );
    4. }
    To copy to clipboard, switch view to plain text mode 

  11. The following user says thank you to jacek for this useful post:

    SkripT (31st March 2006)

  12. #11
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problems updating a dialog

    Thanks jacek I had not thought in this particular solution. That's why I need some suggestions from experienced people Tomorrow I will try it and I will comment the results. What I don't understnad is why emiting a signal in the showEvent (connected to the update method) it doesn't works. The behaviour is simliar at this solution with the timer, no?
    Last edited by SkripT; 31st March 2006 at 23:28.

  13. #12
    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: Problems updating a dialog

    Signals and slots
    When a signal is emitted, the slots connected to it are usually executed immediately, just like a normal function call.
    vs.

    QTimer
    As a special case, a QTimer with a timeout of 0 will time out as soon as all the events in the window system's event queue have been processed. This can be used to do heavy work while providing a snappy user interface.
    Last edited by jpn; 1st April 2006 at 10:21.

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

    SkripT (1st April 2006)

  15. #13
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problems updating a dialog

    Thanks jpn, I didn't knew that. This post has been very useful.

    PD: Finally it works (doing it with the timer)!!!
    Last edited by SkripT; 1st April 2006 at 10:37.

Similar Threads

  1. Issue with Modelless dialog on Mac
    By Satyanarayana Chebrolu in forum Qt Programming
    Replies: 0
    Last Post: 24th February 2009, 10:10
  2. Dialog is not closing
    By manmohan in forum Newbie
    Replies: 5
    Last Post: 1st December 2008, 17:04
  3. [Eclipse/Integration] Project Settings dialog problems
    By BrainB0ne in forum Installation and Deployment
    Replies: 0
    Last Post: 23rd January 2008, 15:52
  4. dialog box
    By Bahar in forum Qt Programming
    Replies: 3
    Last Post: 31st January 2006, 14:52
  5. Updating a QTableWidget through a Dialog
    By dragon in forum Newbie
    Replies: 3
    Last Post: 19th January 2006, 21:16

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.