TextEdit的自定义信号

时间:2019-05-24 13:24:37

标签: python python-3.x pyqt pyqt5

我想使用自定义功能将textedit obj连接到pyqt5中的linedit对象,以便将textedit中的文本转换为纯文本,并将某些文本添加到func中。输出将在行编辑中打印。

我尝试了以下操作(简要显示了自定义信号插槽的一部分)

class asingal(QtCore.QObject):    
    sended=QtCore.pyqtSignal()
    def __init__(self):
        QtCore.QObject.__init__(self)
    def send(self):
         self.sended.connect(self.trigger)
         self.sended.emit()


    def trigger(self)    
         ???

但是我找不到???如何将文本编辑与触发器方法联系起来?

编辑:完整的代码很快就会类似。我想将linedit和textedit连接到一个自定义插槽...

from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(873, 663)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.textEdit = QtWidgets.QTextEdit(self.centralwidget)
        self.textEdit.setGeometry(QtCore.QRect(110, 80, 71, 41))
        self.textEdit.setObjectName("textEdit")
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(130, 160, 55, 16))
        self.label.setText("")
        self.label.setObjectName("label")
        self.pushButton = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton.setGeometry(QtCore.QRect(220, 90, 93, 28))
        self.pushButton.setObjectName("pushButton")
        self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
        self.lineEdit.setGeometry(QtCore.QRect(120, 200, 113, 22))
        self.lineEdit.setObjectName("lineEdit")
    class asignal(QtCore.QObject):

        sended=QtCore.pyqtSignal()
        def __init__(self):
            QtCore.QObject.__init__(self)
        def send(self):
            self.sended.connect(self.trigger)
            self.sended.emit()
        def trigger(self)


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())

编辑:通过以下功能将convert中的self.textEdit.textChanged.connect(self.convert)传递到Ui_MainWindow中的 def convert(self): some_text=self.textEdit.toPlainText() value=int(some_text)**2 self.lineEdit.setText("%s"%value)

$result = $db->query("select id, post, userId from posts");
$posts = [];
while ($post = $result->fetch(PDO::FETCH_OBJECT)) {
    $post->attachments = [];
    $posts[$post->id] = $post;
}

$result = $db->query("select postId, fileName, time from attachments");
while ($att = $result->fetch(PDO::FETCH_OBJECT)) {
    $posts[$att->postId]->attachments[] = $att;
    unset($att->postId); // optional
}

$posts = array_values($posts); // optional
echo json_encode($posts);

0 个答案:

没有答案