PDA

View Full Version : Problem with QDialog modality



Goodwin
31st August 2015, 08:40
Hi everyone!
I want to create a child widget with option to block parent widget.
Lot of people advise to create QDialog with exec_ method and it's cool.
I even tried to set setWindowModality(QtCore.Qt.ApplicationModal)
As result the child widget is always on top of parent, but if I click on parent the child loses his focus.
And the parent widget still can be moved on screen or even minimized in trey.
What's the point of such modality if it's not block parent absolutely?
My Qt - 4.8

prasad_N
31st August 2015, 09:17
Below 2 cases are working fine for me. 4.8 & windows.




#include "mainwindow.h"
#include <QApplication>
#include <QDialog>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();

QDialog* dai = new QDialog;


//You can use either of this
1. dai->setModal(true)
2. dai->setWindowModality(Qt::ApplicationModal);


dai->show();


return a.exec();
}

Goodwin
31st August 2015, 10:10
Thanks man,
((( Your code exactly what I'm doing.

It's so funny I cannot close parent widget, but I still can minimize it and make it fullscreen or move on screen.
I don't understand what is wrong?

anda_skoa
31st August 2015, 12:13
None of these are interactions with the window's content or, depending on the platform, even with the window itself, but the window decoration provided by the windowing system.

It is more like paint events also still being processed in the parent (so it can update itself properly) despite a modal child window.

Cheers,
_

prasad_N
31st August 2015, 12:58
None of these are interactions with the window's content or, depending on the platform, even with the window itself, but the window decoration provided by the windowing system.

It is more like paint events also still being processed in the parent (so it can update itself properly) despite a modal child window.

Cheers,
_

Little messy, But when we set Modality for child window, parent should not get minimized or maximized right ??

anda_skoa
31st August 2015, 17:26
Little messy, But when we set Modality for child window, parent should not get minimized or maximized right ??

Modality prevents the parent window or application (depending on the mode) from receiving user events, such as key presses or mouse events.
Resize events (like paint events or timer events) are generated by the system, thus are not affected by modality.

Cheers,
_