【问题标题】:Error in Python plugin for qgisqgis 的 Python 插件出错
【发布时间】:2013-09-23 04:47:08
【问题描述】:

我正在学习为qgis 开发插件的教程,但是在尝试在文本框窗口中插入文本时遇到了错误。代码如演示here

类vector_selectbypointdialog.py:

    from PyQt4 import QtCore, QtGui
    from ui_vector_selectbypoint import Ui_vector_selectbypoint
    # create the dialog for zoom to point
    class vector_selectbypointDialog(QtGui.QDialog):

    def __init__(self):
        QtGui.QDialog.__init__(self)
        # Set up the user interface from Designer.
        self.ui = Ui_vector_selectbypoint()
        self.ui.setupUi(self)

    def setTextBrowser(self, output):
        self.ui.txtFeedback.setText(output)

    def clearTextBrowser(self):
        self.ui.txtFeedback.clear()

类vector_selectbypoint.py:

init 下创建这样的对象:

# create our GUI dialog
self.dlg = vector_selectbypointDialog()

以及处理插入文本的方法:

handleMouseDown(self, point, button):
        self.dlg.clearTextBrowser()
        self.dlg.setTextBrowser( str(point.x()) + " , " +str(point.y()) )

错误是:

handleMouseDown self.dlg.clearTextBrowser() AttributeError:“vector_selectbypointdialog”对象没有属性“clearTextBrowser”

【问题讨论】:

    标签: python plugins qgis


    【解决方案1】:

    您确定将您的 PyQt 文本浏览器小部件重命名为 txtFeedback 吗?

    【讨论】:

    • 是的。问题在于 clearTextBrowser,它确实存在于代码中,但在 handleMouseDown 中未检测到。
    【解决方案2】:

    我遇到了同样的问题并解决了它:您可能在类 vector_selectbypointDialog 中混合了制表符和空格字符(clearTextBrowser 成为 init() 中的子函数)。

    在 vector_selectbypointdialog.py 中正确缩进你的代码,它会起作用 ;-)

    【讨论】:

      【解决方案3】:

      是的,这个例子有问题。

      代替:

          self.dlg.clearTextBrowser()
          self.dlg.setTextBrowser( str(point.x()) + " , " +str(point.y()) )
      

      只需使用:

          self.dlg.ui.txtFeedback.clear()
          self.dlg.ui.txtFeedback.setText( str(point.x()) + " , " +str(point.y()) )
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-03-20
        • 2014-05-23
        • 2016-06-15
        • 1970-01-01
        • 1970-01-01
        • 2015-05-17
        相关资源
        最近更新 更多