【发布时间】:2020-09-03 23:00:38
【问题描述】:
当我让一个窗口进入全屏模式时,应用程序图标从任务栏中隐藏(在执行 alt-tab 之后)。它也没有出现在alt+tab 窗口中。它只显示了我打开的其他窗口。
当我检查任务管理器时,python 进程在background processes 类别下。我无法切换回窗口。
当我进入全屏模式时,如何阻止应用程序在后台运行?
我的代码:
import sys
from PyQt5.QtGui import QKeySequence
from PyQt5.QtWidgets import QApplication, QLabel, QMainWindow, QShortcut
from PyQt5.QtCore import Qt
# Subclass QMainWindow to customise your application's main window
class MainWindow(QMainWindow):
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.setWindowTitle("Hello fullscreen world")
label = QLabel("Hello fullscreen world")
# The `Qt` namespace has a lot of attributes to customise
# widgets. See: http://doc.qt.io/qt-5/qt.html
label.setAlignment(Qt.AlignCenter)
# Set the central widget of the Window. Widget will expand
# to take up all the space in the window by default.
self.setCentralWidget(label)
self.shortcut_close_window = QShortcut(QKeySequence('F11'), self)
self.shortcut_close_window.activated.connect(self.goFullscreen)
def goFullscreen(self):
if self.isFullScreen():
self.setWindowFlags(self._flags)
self.showNormal()
else:
self._flags = self.windowFlags()
self.setWindowFlags(Qt.WindowCloseButtonHint | Qt.WindowType_Mask)
self.showFullScreen()
app = QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec_()
注意:即使使用 ctrl+c 终止进程或关闭命令提示符也不起作用,只有任务管理器可以。
【问题讨论】:
标签: python-3.x pyqt5