单击复选框时隐藏关键pyqt警告

时间:2014-09-04 08:22:23

标签: python logging pyqt gtk

我在Linux Ubuntu机器(XFCE桌面环境)中使用PyQt4开发GUI。 我使用的是Python 2.7。

除了当我单击一个复选框,此消息显示在控制台中时(即使它不会影响GUI的执行),每件事情都可以正常工作:

(python:9482): Gtk-CRITICAL **: IA__gtk_widget_get_direction: assertion 'GTK_IS_WIDGET (widget)' failed

以下是代码中显示复选框列表的部分:

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

我使用控制台获取一些测试信息。 如何防止出现此消息?

谢谢!

1 个答案:

答案 0 :(得分:3)

我在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以及你的情况。