1

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

类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'

4

3 回答 3

0

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

于 2014-04-18T18:55:38.460 回答
0

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

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

于 2014-05-12T13:54:39.290 回答
0

是的,这个例子有问题。

代替:

    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()) )
于 2014-06-16T19:13:40.340 回答