简体   繁体   English

使用QT4 Designer无法在PyQT4中使用自定义插槽

[英]Can't get custom slot working in PyQT4 with QT4 designer

I am new to PyQT4. 我是PyQT4的新手。

After some tuts I decided to make a simple GUI in which I will enter text in first line and on clicking of Reverse button ,it will show reversed string on second line. 经过一番尝试之后,我决定制作一个简单的GUI,在第一行中输入文本,然后单击“反向”按钮,第二行将显示反向字符串。

I made a custom slot for this,by defining the function in my class.But when I click reverse nothing happens. 通过在类中定义函数,我为此创建了一个自定义插槽。但是当我单击反向时,什么也没有发生。 I have used in-bilt slots for Clear button and Exit button in my GUI and they are working perfectly. 我在GUI中为“清除”按钮和“退出”按钮使用了计费中插槽,它们运行良好。

If someone can just clarify this custom slot problem it would help me advance further. 如果有人可以澄清这个自定义插槽问题,它将帮助我进一步发展。

Thanks in advance. 提前致谢。

Here's a photo of my GUI 这是我的GUI的照片

http://img196.imageshack.us/img196/7131/diall.png http://img196.imageshack.us/img196/7131/diall.png

Stringreverse.py Final File Stringreverse.py最终文件

import sys
from PyQt4 import QtCore, QtGui



from stringreverse_ui import Ui_Dialog

    class MyForm(QtGui.QMainWindow):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.ui=Ui_Dialog()
        self.ui.setupUi(self)
    QtCore.QObject.connect(self.ui.pushButton_3,QtCore.SIGNAL("Click()"), self.reverse)



    def reverse(self):
        s=self.ui.lineEdit_2.text()
        self.ui.lineEdit.setText(s[::-1])




if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    myapp = MyForm()
    myapp.show()
    sys.exit(app.exec_())enter code here

尝试使用QtCore.SIGNAL("clicked()")代替QtCore.SIGNAL("Click()")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM