使用 show 方法未显示 python-form [英] python-form not displayed using show method

查看:47
本文介绍了使用 show 方法未显示 python-form的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 QGIS 的 Python 插件.我的主要表单为 DlgQueryBuilder.py,另一个表单为 DlgDberror.py,它显示查询中的错误.我的DlgDberror.py包含以下内容:

I am working with python plugins for QGIS.I have my main form as DlgQueryBuilder.py and another form as DlgDberror.py,which displays the error in the query.My DlgDberror.py contains following:

class DlgDbError(QtGui.QWidget, Ui_DlgDbError):
def __init__(self,e,parent):


    QtGui.QWidget.__init__(self)
    Ui_DlgDbError.__init__(self)
    self.setupUi(self)
    msg = "<pre>" + e.msg.replace('<','&lt;') + "</pre>"


    self.txtMessage.setHtml(msg)



@staticmethod
def showError(e, parent):

    dlg = DlgDbError(e,parent)
    dlg.show()

来自 DlgQueryBuilder.py 的调用是DlgDbError.showError(e, self)"一切都很顺利,但是当我尝试运行我的主表单 DlgQueryBuilder.py 时,*DlgDberror.py* 表单没有显示.它会在一秒钟内消失.dlg.show() 应该正常工作??

The call to this from DlgQueryBuilder.py is "DlgDbError.showError(e, self)" Everything goes smooth but when i try to run my main form DlgQueryBuilder.py,*DlgDberror.py* form is not shown.It dissapears within a second. dlg.show() should work rite??

推荐答案

showError 退出时,dlg 被垃圾收集并消失,这也会破坏底层的 Qt 对象和对话框.我怀疑您需要以某种方式将对话框传递回 QGIS,以便它可以处理对话框所需的任何内容.所以是的,show() 可以工作,但是您的程序正在破坏对话框,然后才能执行任何有用的操作.

When showError exits, dlg is garbage collected and goes away which also destroys the underlying Qt objects and the dialog. I suspect you need to pass your dialog back to QGIS in some way so it can handle whatever is necessary with the dialog. So yes, show() works, but your program is destroying the dialog before it can do anything useful.

也许你想要 exec_() 代替?它将弹出对话框,然后阻止等待用户关闭对话框.这称为模态对话框.请参阅 http://www.riverbankcomputing.co.uk/static/文档/PyQt4/html/qdialog.html

Perhaps you wanted exec_() instead? It will pop up the dialog and then block waiting for the user to close the dialog. This is known as a modal dialog. See http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qdialog.html

这篇关于使用 show 方法未显示 python-form的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆