我看到每次与PyQt5交互时,PyQt5中的文件对话框小部件都会向命令行注销QWindowsNativeFileDialogBase::onSelectionChange (QUrl...)
消息。有办法阻止这种情况发生吗?
您可以看到,当我单击“ codetesting.py”时,该消息会在命令行中弹出。
QWindowsNativeFileDialogBase::onSelectionChange (QUrl("file:///C:/Users/user/Documents/WaferMapViewerProject/src/main/python/codetesting.py")) 1
运行此代码时,会弹出一个窗口,中间有一个按钮。单击文件对话框将打开。
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QFileDialog
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import pyqtSlot
class App(QWidget):
def __init__(self):
super().__init__()
self.title = 'PyQt5 button - pythonspot.com'
self.left = 50
self.top = 50
self.width = 320
self.height = 200
self.initUI()
def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
button = QPushButton('PyQt5 button', self)
button.setToolTip('This is an example button')
button.move(100, 70)
button.clicked.connect(self.on_click)
self.show()
@pyqtSlot()
def on_click(self):
print('PyQt5 button click')
fname = QFileDialog.getOpenFileName()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())
答案 0 :(得分:2)
您可以使用QLoggingCategory
禁用日志记录:
from PyQt5.QtCore import QLoggingCategory
QLoggingCategory.setFilterRules('qt.qpa.dialogs.debug=false')
或
import os
# ...
if __name__ == '__main__':
os.environ["QT_LOGGING_RULES"] = "*.debug=false"
app = QApplication(sys.argv)
# ...