我正在 Linux Ubuntu 机器(XFCE 桌面环境)中使用 PyQt4 开发 GUI。 我正在使用 Python 2.7。
一切正常,除了当我单击一个复选框时,此消息显示在控制台中(即使它不影响 GUI 的执行):
(python:9482): Gtk-CRITICAL **: IA__gtk_widget_get_direction: 断言 'GTK_IS_WIDGET (widget)' 失败
这是显示复选框列表的代码的一部分:
def SFCheckList(self):
groupBox = QtGui.QGroupBox("SF Functions List")
self.grid = QtGui.QGridLayout()
self.checkBoxList = [[], []]
#Reading supported SF functions
try:
sql = "SELECT SF FROM Locators"
cursor.execute(sql)
results = cursor.fetchall()
except:
print "Error: unable to fecth data (SF Functions)"
#Building the Checkbox List
for SF in results:
self.checkBoxList[0].append(QtGui.QCheckBox(SF[0]))
self.checkBoxList[1].append(SF[0])
self.SFCheckListDisplay()
groupBox.setLayout(self.grid)
return groupBox
def SFCheckListDisplay(self):
l = sqrt(len(self.checkBoxList[0]))
if(l!=int(l)):
l= int(l) + 1
i=0
j=0
for cb in self.checkBoxList[0]:
self.grid.addWidget(cb, i, j)
j+=1
if(j==l):
i+=1
j=0
我正在使用控制台获取一些测试信息。 如何防止出现此消息?
谢谢!
最佳答案
我在 Windows 7 PyQt5 上遇到了类似的问题:
import sys
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
class Window(QWidget):
def __init__(self, *args, **kwargs):
QWidget.__init__(self, *args, **kwargs)
self.stderr_backup = None
self.label = QLabel("Test", self)
self.layout = QHBoxLayout()
self.layout.addWidget(self.label)
self.setLayout(self.layout)
self.show()
app = QApplication(sys.argv)
win = Window()
sys.exit(app.exec_())
Qt 的错误消息如下,但应用程序仍然正常运行。
QWindowsWindow::setGeometry: Unable to set geometry 42x35+520+270 on QWidgetWindow/'WindowClassWindow'. Resulting geometry: 112x35+520+270 (frame: 8, 29, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 42x35, maximum size: 16777215x16777215).
我可以使用以下方式禁用该消息:
def handler(msg_type, msg_log_context, msg_string):
pass
PyQt5.QtCore.qInstallMessageHandler(handler)
但是,我不确定这是否适用于 PyQt4 以及您的情况。
关于python - 单击复选框时隐藏严重的 pyqt 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25660597/