0

I am making an application in Qt using PySide. In my main.py I have a class called Program which sets up the ui and I have another class which has functions pertaining to a certain area. For instance I have an area which has a start and a clear button. I define the functions in class RunArea and connect the signals in class Program but nothing happens. Here is the code.

class Program(QtGui.QMainWindow, Interface.Ui_MainWindow):
    def __init__(self, parent=None):
        super(Program, self).__init__(parent)
        self.setupUi(self)

        self.runArea = RunArea()
        self.startButton.clicked.connect(self.runArea.start)
        self.clearButton.clicked.connect(self.runArea.clear)


class RunArea(QtGui.QMainWindow, Interface.Ui_MainWindow):
    def __init__(self, parent=None):
        super(RunArea, self).__init__(parent)
        self.setupUi(self)

    def start(self):
        self.log.setPlainText("log entry")

    def clear(self):
        self.runTree.clear()

What I expect to happen is that "log entry" will be put in a QTextEdit(defined in setupUi) when I click start. And when I click clear a TreeWidget with name runTree will be cleared. I know that the signals are working, but nothing is showing up. May someone please explain why it is not working?

4

1 に答える 1

0

コードが機能しない理由/方法は正確にはわかりませんが、両方のクラスで同じオブジェクトを参照していない継承に関係があると思われます。
ただし、これを行う方法は次のとおりです。

class Program(QtGui.QMainWindow, Interface.Ui_MainWindow):
    def __init__(self, parent=None):
        super(Program, self).__init__(parent)
        self.setupUi(self)

        self.runArea = RunArea(self)
        self.startButton.clicked.connect(self.runArea.start)
        self.clearButton.clicked.connect(self.runArea.clear)


class RunArea():
    def __init__(self, parent=None):
        self.parent = parent

    def start(self):
        self.parent.log.setPlainText("log entry")

    def clear(self):
        self.parent.runTree.clear()
于 2013-01-23T17:59:25.603 に答える