How to set modality to QWidget
-
Hello, i'm working actually into software, and i need to set modality for class inherit to QWidget, because i wouldn't like user can input into previous Widget
Is it mandatory and better to inherit to QDialog?
-
You can edit the QWidget's
windowModality
property: https://doc.qt.io/qt-5/qwidget.html#windowModality-prop -
Yes,i have seen that, but when i do setWindowModality(Qt::WindowModal);, nothing, the previous window is available.
Look:
void MainWindow::initialize() { setWindowTitle("Caisse"); //setWindowIcon(QIcon("")); setWindowFlags(Qt::WindowMinimizeButtonHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint); setWindowModality(Qt::WindowModal); initialize_pointers(); setLayout(main_layout); }
-
Hi,
Without the rest of the code it's going to be difficult find what is going wrong.
-
Hi
You can also use
setWindowModality(Qt::ApplicationModal); -
Oh yes perfect! Thanks you very much!
-
@JKSH
Hi
while we talk about Qt::WindowModality
Since have to give a QWidget no parent to have be a window, how would
setWindowModality(Qt::WindowModal);
Be able to work as it has no parent then?
Do you know the secret :) ?@Fulgurance said in How to set modality to QWidget:
Oh yes perfect! Thanks you very much!
Great! Happy coding :)
@mrjj said in How to set modality to QWidget:
while we talk about Qt::WindowModality
Since have to give a QWidget no parent to have be a window, how would
setWindowModality(Qt::WindowModal);
Be able to work as it has no parent then?
Do you know the secret :) ?Ha! I didn't even think about that.
Qt::WindowModal
is probably useless for widgets that don't inheritQDialog
. -
@JKSH
Hi
while we talk about Qt::WindowModality
Since have to give a QWidget no parent to have be a window, how would
setWindowModality(Qt::WindowModal);
Be able to work as it has no parent then?
Do you know the secret :) ? -
@mrjj
Actually a QWidget can be a window and have a parent at the same time.
It just need to haveQt::Window
flag set.
And it acts similar to aQDialog
(which also have Qt::Window flag) with a parent.@Bonnie said in How to set modality to QWidget:
Actually a QWidget can be a window and have a parent at the same time.
It just need to haveQt::Window
flag set.
And it acts similar to aQDialog
(which also have Qt::Window flag) with a parent.Well-spotted. Thanks!