【发布时间】:2023-02-02 18:39:01
【问题描述】:
我想要切换子窗口的 WindowTransparentForInput 语句。 在下面的代码中,我写道,子窗口将关闭而不是切换语句。
你能指出问题所在吗?
import sys
from PyQt5 import QtWidgets as qtw, QtGui as qtg, QtCore as qtc
class Main(qtw.QWidget):
def __init__(self):
super().__init__()
self.mainWindow = qtw.QWidget(self)
self.mainWindow.setGeometry(100,100,200,200)
label = qtw.QLabel('Main window', self)
self.switch = qtw.QCheckBox('Transparent for input on sub window', self)
self.switch.setChecked(False)
self.switch.stateChanged.connect(self.switchAction)
mainLayout = qtw.QVBoxLayout()
self.setLayout(mainLayout)
mainLayout.addWidget(label)
mainLayout.addWidget(self.switch)
self.subwindow = qtw.QWidget()
self.subwindow.setGeometry(150,100,200,200)
sublabel = qtw.QLabel('Sub window', self.subwindow)
self.show()
self.subwindow.show()
def switchAction(self):
if self.switch.isChecked:
self.subwindow.setWindowFlags(qtc.Qt.WindowTransparentForInput | qtc.Qt.FramelessWindowHint)
else:
self.subwindow.setWindowFlags(qtc.Qt.FramelessWindowHint)
if __name__ == '__main__':
app = qtw.QApplication(sys.argv)
mw = Main()
sys.exit(app.exec())
【问题讨论】:
标签: pyqt5