PDA

View Full Version : Creating modal dialogs



Luc4
9th June 2010, 11:07
Hi! I created a subclass of a QDialog to create a custom one. I inherited QDialog and built it with Qt::Dialog window flag. After that, before using exec(), I set window modality to ApplicationModal. However, I still get that the dialog stays on top and the rest of the application which is in the background is still usable. What can there be wrong? I can't find in the documentation anything I'm missing.

Thanks!

high_flyer
9th June 2010, 11:33
I inherited QDialog and built it with Qt::Dialog window flag
You don't have to do that if you inherit QDialog, since it is already set by QDialog.


What can there be wrong?
Hmm.. can you show your code?

Luc4
9th June 2010, 12:51
[Sorry, made a mistake, submitted twice]

Luc4
9th June 2010, 12:52
This is how I build the class:


CustomMessageBox customMessageBox(..., parent, Qt::Dialog);
customMessageBox.setWindowModality(Qt::Application Modal);
customMessageBox.exec();

and the constructor is:


CustomMessageBox::CustomMessageBox(..., QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f) {
this->resize(...);
this->move(...);
this->setWindowFlags(Qt::FramelessWindowHint);
this->setAttribute(Qt::WA_TranslucentBackground, true);
// ...
}

The ... stands for some other instructions, such as creating some buttons, pixmaps etc...
The class inherits QDialog, I defined it as:


class CustomMessageBox : public QDialog {
// ...
}

Any idea what I'm doing wrong? (I'm working under Windows CE)
Thanks!

high_flyer
9th June 2010, 14:01
Try running this on another system which is not CE, and see if it behaves the same...
I see nothing in the code you posted that should not allow it to be application modal.
Another possibility is that the frame-less flag somehow interferes.
Try it with normal window decorations, and see if it behaves the same.
Try also with out the WA_TranslucentBackground property.

amoswood
9th June 2010, 16:26
This is how I build the class:


CustomMessageBox customMessageBox(..., parent, Qt::Dialog);
customMessageBox.setWindowModality(Qt::Application Modal);
customMessageBox.exec();

One of the issues might be that calling the exec() function changes the modality of the window to Qt::WindowModal. If you want to make it ApplicationModel, then simply replace exec() with show().

girishgowda
10th June 2010, 11:01
Luc,

Please specify what is the operation you are able to do on the application behind the dialog...
Is it touch event or the key event?

If key event, then it could be a chance that the event is not being consumed by the top most widget, thus the event propogates to the widgets in the lower levels...

Please clarify

-Girish

Luc4
11th June 2010, 17:58
The behavior I'm seeing is that the window is always on top, but the window below is active, which means it reacts to clicks.
I made some tests and it seems that setting the parent to NULL and removing Qt::FramelessWindowHint make it work correctly. Is this the expected behavior?
Thanks for your help!

Luc4
17th June 2010, 11:35
Unfortunately I need Qt::FramelessWindowHint and I need to set the parent (otherwise I wouldn't have transparency). Any solution?