PDA

View Full Version : Problems updating a dialog



SkripT
30th March 2006, 11:06
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.

zlatko
30th March 2006, 11:30
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

SkripT
30th March 2006, 11:37
... 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?

zlatko
30th March 2006, 12:20
Ok show you available now code maiby problem will be easier :)

SkripT
30th March 2006, 12:34
That's the code for both widgets of the dialog:

This method is to update the contents of the widget:

void ImageWindow::updateWindow()
{
if (fotoValida && taulaValida) return;
QProgressDialog progres("Carregant imatge i actualitzant informació...", 0, 0, 3, this);
progres.setMinimumDuration(0);

progres.setValue(1);

if (!fotoValida)
{
butoEditorFoto -> setEnabled(foto -> fixaFoto(QImage(pathFoto)/*.scaled(tamIniAreaFoto, Qt::KeepAspectRatio)*/));
fotoValida = true;
}

progres.setValue(2);

if(!taulaValida)
{
omplirParamsFitxer();
omplirParamsRetallat();
taulaValida = true;
}

progres.setValue(3);
}

That's how I reimplement the showEvent:

void ImageWindow::showEvent(QShowEvent *event)
{
if (!event -> spontaneous())
updateWindow();
}

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.

SkripT
30th March 2006, 13:43
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:

void ImageWindowsDialog::showEvent(QShowEvent *event)
{
if (!event -> spontaneous())
{
finestraFoto -> hide();
finestraFotoOriginal -> hide();

show();

repaint();
qApp -> processEvents();
finestraFoto -> show();
finestraFotoOriginal -> show();

}
}

"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??? :confused:

SkripT
31st March 2006, 00:25
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

SkripT
31st March 2006, 12:15
Hi again, let's see if this time I have more luck :p 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.

SkripT
31st March 2006, 19:50
Nobody could suggest me something? :( :crying: :eek: :o

jacek
31st March 2006, 20:04
Try adding a single shot timer with 0 timeout in showEvent:
void ImageWindowsDialog::showEvent( QShowEvent * event ) {
QDialog::showEvent( event );
QTimer::singleShot( 0, this, SLOT( startUpdate() ) );
}

SkripT
1st April 2006, 00:24
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?

jpn
1st April 2006, 06:11
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.

SkripT
1st April 2006, 11:17
Thanks jpn, I didn't knew that. This post has been very useful.

PD: Finally it works (doing it with the timer)!!!