在模态对话框中激活的全局应用程序菜单(在 Linux 上) [英] Global application menu active in modal dialog box (on Linux)

查看:79
本文介绍了在模态对话框中激活的全局应用程序菜单(在 Linux 上)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Windows 和 Linux (Ubuntu) 上的 PySide 中开发应用程序.在 Windows 上,一切都按预期工作.但是在 Linux 上,当我在应用程序中打开模式对话框(甚至是系统对话框,例如 OpenFileDialog)时,全局应用程序菜单仍然保持可见和活动状态.那么模态是什么意思呢?

我知道这可能与此重复:即使打开模态对话框也启用应用程序菜单

按照它,如果我理解得好,我将不得不在每个对话框中保留对全局应用程序菜单的引用,并在打开模态对话框时禁用所有菜单操作.并在关闭时启用它.很难相信这是唯一的选择.这只是愚蠢的矫枉过正...

那么有没有其他选择来解决它?例如,将菜单栏保持在我们在 Windows 上的主窗口标题栏下方......我知道这可能不是原生 Linux 的感觉和外观",但它比在模态窗口中拥有全局菜单要好得多.

还是我错过了一些简单而明显的解决方案?

解决方案

您实际上可以通过禁用 QMenu.nativeMenuBar 属性将菜单栏保持在窗口标题正下方以避免此问题.>

这是 PyQt4 的示例:

from PyQt4 import QtGui类 MainWindow(QtGui.QMainWindow):def __init__(self, parent = None):super(MainWindow, self).__init__(parent)menu_bar = self.menuBar()# 在 Ubuntu 上停用全局菜单栏menu_bar.setNativeMenuBar(False)# 添加显示菜单menu_bar.addMenu('一些菜单...').addAction('打我!')# 打开模态对话框进行测试self.button = QtGui.QPushButton('打开对话框', self)self.setCentralWidget(self.button)self.button.clicked.connect(lambda: QtGui.QMessageBox.information(self, 'Hello!', "I'm really modal"))如果 __name__ == '__main__':导入系统app = QtGui.QApplication(sys.argv)w = 主窗口()w.show()sys.exit(app.exec_())

I am developing an application in PySide on Windows and Linux (Ubuntu). On Windows everything works as expected. But on Linux, when I open a modal dialog box in the application (even system dialogs, e.g. OpenFileDialog), the global application menu still stays visible and active. What is the meaning of modality then?

I know this is likely a duplicate to this: Application menu is enabled even if a modal dialog box is open

According to it, if I understand well, I would have to keep the reference to the global application menu in each dialog box and disable all the menu actions when the modal dialog box is opened. And enable it when it is closed. Hard to believe this is the only option. It is just stupid overkill...

So is there any other option how to solve it? For example keeping the menu bar below the main window title bar as we have in on Windows... I know it may be not native Linux "feel and look" then but it is much better than having global menu in modal windows.

Or am I missing some simple and obvious solution?

解决方案

You can actually keep the menu bar right below the window title to avoid this problem by disabling the QMenu.nativeMenuBar property.

Here is an example with PyQt4:

from PyQt4 import QtGui


class MainWindow(QtGui.QMainWindow):

    def __init__(self, parent = None):
        super(MainWindow, self).__init__(parent)

        menu_bar = self.menuBar()
        # Deactivate global menu bar on Ubuntu
        menu_bar.setNativeMenuBar(False)
        # Add menu for show
        menu_bar.addMenu('Some menu...').addAction('Hit me!')

        # Open modal dialog for test
        self.button = QtGui.QPushButton('Open dialog', self)
        self.setCentralWidget(self.button)
        self.button.clicked.connect(
            lambda: QtGui.QMessageBox.information(self, 'Hello!', "I'm really modal")
            )


if __name__ == '__main__':
    import sys

    app = QtGui.QApplication(sys.argv)

    w = MainWindow()
    w.show()

    sys.exit(app.exec_())

这篇关于在模态对话框中激活的全局应用程序菜单(在 Linux 上)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆