Issue
I have a python plugin where the main.py
file displays a QTextBrowser and writes some text. This works fine.
I wrote a second file anotherFile.py
which identifies the same QTextBrowser but cannot write any text to it. Perhaps it needs to take ownership, I'm not sure?
Here is the code used:
# main.py #
from Example_dockwidget import ExampleDockWidget
from anotherFile import anotherClass
class Example:
def __init__(self, iface):
self.iface = iface
def function(self):
self.dockwidget = ExampleDockWidget()
self.dockwidget.show()
textBrowser = self.dockwidget.textBrowser
#textBrowser.setText('This works!')
a = anotherClass(self)
a.anotherFunction()
# anotherFile.py #
from Example_dockwidget import ExampleDockWidget
class anotherClass:
def __init__(self, iface):
self.iface = iface
self.dockwidget = ExampleDockWidget()
def anotherFunction(self):
textBrowser = self.dockwidget.textBrowser
textBrowser.setText('This does not work!')
print 'Why?'
# Example_dockwidget.py #
FORM_CLASS, _ = uic.loadUiType(os.path.join(
os.path.dirname(__file__), 'Example_dockwidget_base.ui'))
class ExampleDockWidget(QtGui.QDockWidget, FORM_CLASS):
def __init__(self, parent=None):
super(ExampleDockWidget, self).__init__(parent)
self.setupUi(self)
Solution
Your two classes both create their own ExampleDockWidget
. Only one of them is shown (has its show
method called) but there are two.
So it's not surprising that text sent to one does not appear on the other. You need to arrange for your anotherClass
object to obtain a reference to the other ExampleDockWidget
so it can share the same one.
Answered By - strubbly
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.