I have an application with some windows, and one of them is modal. On Windows OS, when I minimize the modal window all other windows minimize as well. On Linux (I’m using Astra Linux) only the modal window minimizes and all other windows state doesn’t change, and they are not available for any action, like if they were disabled. What’s wrong with me or Astra Linux? How can I do same minimize-action in Astra Linux?
Advertisement
Answer
You may want to override the changeEvent
method of the modal widget to catch a WindowStateChange
event, check the widget state and, if minimized, force all other top level widgets to minimize as well (if not, restore all windows):
#include <QEvent> #include <QApplication> void Form::changeEvent(QEvent * event) { if(event->type() == QEvent::WindowStateChange) { QWidgetList list = QApplication::topLevelWidgets(); if(isMinimized()) { for(int i=0; i<list.size(); i++) { if(!list.at(i)->isMinimized()) { list[i]->setWindowState(Qt::WindowMinimized); } } } else { for(int i=0; i<list.size(); i++) { if(list.at(i)->isMinimized()) { list[i]->activateWindow(); //or: //list[i]->setWindowState(Qt::WindowActive); } } } } }