PDA

View Full Version : Problems with a dialog



SkripT
27th March 2006, 17:42
Hi all, I've got a widget that opens a dialog. This dialog shows a QProgressDialog in some moments when the user wants to do some actions. I've noticed a problem with this dialog: if i don't exec the dialog, the progressdialog is shown correctly but if I exec the dialog from the widget, the progressbar is not shown like if it's hidden by the dialog. Well, exactly the progressdialog is shown for a seconds (1 or 2) and then is hidden forced. Anybody knows why or where's the mistake?

Thanks.

jpn
27th March 2006, 17:59
From QProgressDialog docs (http://doc.trolltech.com/4.1/qprogressdialog.html#details):


The dialog automatically resets and hides itself at the end of the operation. Use setAutoReset() (http://doc.trolltech.com/4.1/qprogressdialog.html#autoReset-prop) and setAutoClose() (http://doc.trolltech.com/4.1/qprogressdialog.html#autoClose-prop) to change this behavior.

SkripT
27th March 2006, 18:06
From QProgressDialog docs (http://doc.trolltech.com/4.1/qprogressdialog.html#details):

Thanks jpn, but that's not the problem. I also know it. As I said is like if the progressdialog is hidden because the dialog is forced at the top of the widget's stack. The cause could probably be because it's modal. Is it true?

SkripT
28th March 2006, 15:55
Hi again, I've updated to Qt4.1.1 but the problem with the progress dialog still presists. It's very strange because the progress dialog attempts to appear, as I commented previously it appears for 1 second but it disappears suddenly (not because it has finished) like if it's obscured for its parent dialog. I've tried to call raise of the progress dialog but it doesn't work. Anybody could tell me why or where's the mistake? Could the cause be that dialog that opens the progress dialog is executed?

jacek
28th March 2006, 16:23
Does your program enter some kind of a loop after it shows that progress dialog?

SkripT
28th March 2006, 17:01
Does your program enter some kind of a loop after it shows that progress dialog?


I have to add that the progress dialog is used not for the dialog itself but for a child widget of this dialog, but I don't think that this could cause the problem. The progress dialog is created in the creation of the child widget, where I set its minimum duration and its range. Then is shown by calling QProgressDialog::setValue in the methods where I use it. I have to do it in this way because I need to subclass this child widget and each class has its own text for the QProgressDialog but its range and minimum duration is equal. Also the progress dialog is used in the main class not in these subclasses.

jacek
28th March 2006, 17:14
Could you show some code?

SkripT
28th March 2006, 17:33
Could you show some code?

Well it's a little long but I show how I use the progress dialog:


FinestraFoto::FinestraFoto(QWidget *parent)
: QWidget(parent)
{
(.......)
progres.setRange(0, 3);
progres.setCancelButtonText(0);
progres.setMinimumDuration(0); // I want to show it always
(.........)
}

That's how I declare ithe progress dialog.


void FinestraFoto::actualitzarFinestra(bool actualitzarFoto, bool actualitzarParamsFitxer,
bool actualitzarParamsRetallat)
{
if (!actualitzarFoto && !actualitzarParamsFitxer && !actualitzarParamsRetallat) return;

progres.setValue(1);

if (actualitzarFoto)
{
tamIniAreaFoto = fotoArea -> maximumViewportSize();
butoEditorFoto -> setEnabled(foto -> fixaFoto(QImage(pathFoto).scaled(tamIniAreaFoto, Qt::KeepAspectRatio)));
}

progres.setValue(2);

if(actualitzarParamsFitxer)
omplirParamsFitxer();
if(actualitzarParamsRetallat)
omplirParamsRetallat();

progres.setValue(3);
}

And that's how I use it everytime "actualitzarFinestra" is called.

then I have 2 subclasses of FinestraFoto where I set the text of the progress dialog for each of them. These subclasses use "FinestraFoto::actualitzarFinestra" method and these widgets are part of the modal dialog. I attach an example of the dialog window, where you can see that these two subclasses correspond with each "image" window. And the progress bars are shown when each image is loaded and each table is filled.

jacek
28th March 2006, 17:44
progres.setValue(2);

if(actualitzarParamsFitxer)
omplirParamsFitxer();
if(actualitzarParamsRetallat)
omplirParamsRetallat();

progres.setValue(3);
Do you allow Qt to process events between subsequent calls to setValue()?

SkripT
28th March 2006, 17:55
Do you allow Qt to process events between subsequent calls to setValue()?

I don't understand what you mean jacek. The documentation explains that the progress dialog can be used this way:

QProgressDialog progress("Copying files...", "Abort Copy", 0, numFiles, this);
for (int i = 0; i < numFiles; i++) {
progress.setValue(i);
qApp->processEvents();

if (progress.wasCanceled())
break;
//... copy one file
}
progress.setValue(numFiles);

jpn
28th March 2006, 18:16
Notice the statement on line 4..
Do you call QApplication::processEvents() anywhere?

SkripT
28th March 2006, 18:26
Notice the statement on line 4..
Do you call QApplication::processEvents() anywhere?

You are right jpn, but I've tried it calling to processEvents after setting each value and the progress dialog is not shown (appears for only one second and then is hidden suddenly) Moreover I think that the processEvents statement is to caught when the user press the cancel button but I have disabled it :eek: :confused: :(

jacek
28th March 2006, 20:26
Try calling progres.raise() before setValue().

jpn
28th March 2006, 20:47
Moreover I think that the processEvents statement is to caught when the user press the cancel button but I have disabled it :eek: :confused: :(
Actually, if you want your application to response to any user interaction, you will have to let it to process it's events once in a while. Besides of moving the windows/dialogs and so on, this user interaction includes also redrawing e.g. when switching between different applications.

SkripT
29th March 2006, 10:56
Thanks jpn and jacek. Finally I've found the problem. Before, I was creating the progress dialog with no parent (0). But if I create the progress dialog everytime on "actualitzarFinestra" and set its parent to "this", it's shown. Really strange, don't you think? :confused:

jacek
29th March 2006, 14:12
I was creating the progress dialog with no parent (0). But if I create the progress dialog everytime on "actualitzarFinestra" and set its parent to "this", it's shown.
Do you invoke the show() method?

SkripT
29th March 2006, 14:17
Do you invoke the show() method?

Good suggestion jacek, but I've tried it calling to show but it neither appears (it's hidden after 1 sec)....