我用的是PyQt4。我可以通过点击一个图标来最小化窗口,但我不能最小化它。在
程序由py2exe编译,显示为“python.exe“在任务栏中。如何捕捉单击事件?在
我正在使用QWebView。事件QWebView.event(e)
没有帮助。在
下一个代码提供窗口状态更改事件:
...
class LauncherView(QWebView, object):
def __init__(self, QWidget_parent=None):
super(LauncherView, self).__init__(QWidget_parent)
self.setWindowFlags(Qt.FramelessWindowHint)
self.setContextMenuPolicy(Qt.CustomContextMenu)
self.resize(801, 601)
...
def event(self, e):
if e.type() == e.WindowStateChange and self.windowState() & QtCore.Qt.WindowMinimized: # Event if I click the minimize button
self.showMinimized()
elif e.type() == e.WindowStateChange and self.windowState() == QtCore.Qt.WindowNoState: # Event if I restore the window by clicking on taskbar
self.showMaximized() # or showNormal
elif ???????: # What event I must catch if I want to minimize window by clicking on taskbar? Now it does not occur...
self.showMinimized()
return super(QWebView, self).event(e)
...
def Main(*args):
app = QApplication(args)
app.setWindowIcon(QIcon('icon.png'))
view = LauncherView()
view.setWindowTitle('*** Launcher')
frame = view.page().mainFrame()
JavaScript = JSCaller(view)
events = PyEvents(view, JavaScript)
Python = PyCaller(events)
html = HTML_data()
thisDirPath = 'file:///' + getCurrentPath() + '/Views/'
view.setHtml(html, QtCore.QUrl(thisDirPath))
frame.addToJavaScriptWindowObject('Python', Python)
frame.evaluateJavaScript("Python.Print('Python context works normally');")
view.show()
app.exec_()
if __name__ = '__main__':
Main(*sys.argv)
您无法使用任务栏图标最小化应用程序的原因是您已经覆盖了现有的窗口标志。在
现在,通常你会做
self.setWindowFlags(self.windowFlags()|Qt.FramelessWindowHint)
,但是我测试了这个,当不该显示的时候,框架就会显示出来。可能是现有标志之一与无框架标志冲突。在所以,至少你需要有这些标志:
一旦你有了这个,你就不需要任何特殊的代码来通过点击任务栏图标来最小化/最大化窗口。在
您可能还需要其他标志来获得其他行为。您可以在这里看到完整的列表:http://qt-project.org/doc/qt-4.8/qt.html#WindowType-enum
相关问题 更多 >
编程相关推荐