Reputation: 106
I am developing a desktop application on macOS. I have a class that is a subclass of QMainWindow. Inside this window there are many dockwidgets. I need to set WindowModality to WindowModal, so user cannot interact with other opened windows. But my window has a menubar with many menus that have some QActions inside and when I setWindowModality(Qt::WindowModal) it automatically disables every action in menu and I need them to be enabled.
Can anybody provide some simple solution for this? Or it is not possible?
Thank you very much.
EDIT:
I have many windows in my application. I have a real main window from which you can open another window and also from that window another window. And here is the situation where i need my child windows to be modal. But they also have their own menubar which gets automatically disabled when window modality is turned on. Ive been googling it already maybe for 10 hours without any solution. I cannot test it but I guess that on windows the menubar would not disable because the native menu is quite different.
Upvotes: 1
Views: 743
Reputation: 1
Please consider the usage of Qt::ApplicationModal.
This keeps the modality but gives you other behaviour on MAC.
Upvotes: -2
Reputation: 1174
If there is no specific need of using QWindow
, then it'll be easier to achive this using QDialog
class instead. Using QDialog
you can simply show dialog as modal using exec()
method.
EDIT: Basically, you can add QMenuBar
element to every QLayout
class object using QLayout::setMenuBar
method.
If you want to add menu bar to QDialog
, you've got to set layout for your dialog, then programatically create desired QMenuBar
object and pass it to QDialog
layout (which you can access using QDialog::layout
method). Simple example below:
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
QMenuBar* menu = new QMenuBar();
QMenu* fileMenu = menu->addMenu("File"); //Create 'File' menu inside menu bar
QAction* closeAction = fileMenu->addAction("Close"); //Create 'Close' action in 'File' menu
connect(closeAction, QAction::triggered, this, close); //Close dialog after triggering 'Close' action
layout()->setMenuBar(menu); //Add menu bar to QDialog layout
}
Upvotes: -1