简体   繁体   English

从系统任务栏应用程序菜单中打开QDialog

[英]Open QDialog from system tray application menu

I'm trying to open a QDialog from an option in a system tray menu (QtGui.QMenu). 我正在尝试从系统任务栏菜单(QtGui.QMenu)中的选项打开QDialog。 But my original class 'Mensageiro' is derived from QtGui.QSystemTrayIcon and so I get an Exception when I create the QDialog instance: 但是我的原始类'Mensageiro'是从QtGui.QSystemTrayIcon派生的,因此在创建QDialog实例时出现异常:

TypeError: 'PySide.QtGui.QDialog' called with wrong argument types:
   PySide.QtGui.QDialog(Mensageiro)
Supported signatures:
   PySide.QtGui.QDialog(PySide.QtGui.QWidget = None, PySide.QtCore.Qt.WindowFlags = 0)

What can I do to open the dialog? 我该怎么办才能打开对话框? I don't want it to be parentless. 我不希望自己没有父母。

The solution was actually very simple. 该解决方案实际上非常简单。 Even a system tray application needs a QWidget as its parent. 甚至系统任务栏应用程序也需要QWidget作为其父项。 The parent widget remains hidden. 父窗口小部件保持隐藏。 So I create the QDialog as a child of the same parent widget: 因此,我将QDialog创建为同一父小部件的子级:

self.dialog = dialogos.DialogExemplo(self.parent)

When I close the tray application with an "exit" option, the following code is executed: 当我使用“退出”选项关闭托盘应用程序时,将执行以下代码:

 self.application.setQuitOnLastWindowClosed(True)
 # Hide the tray icon before it is destroyed
 self.hide()
 # Close the parent widget, killing all open windows.
 self.parent.close()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM