J'essaie d'implémenter une fonction. Mon code est donné ci-dessous. Je veux obtenir le texte en ligne avec le nom d'objet 'host' dans une chaîne par exemple 'shost' quand l'utilisateur clique sur le bouton avec le nom 'connect'. Comment puis-je faire ceci? J'ai essayé et échoué. Comment puis-je implémenter cette fonction?Comment obtenir du texte dans QlineEdit lorsque QpushButton est enfoncé dans une chaîne?
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class Form(QDialog):
def __init__(self, parent=None):
super(Form, self).__init__(parent)
le = QLineEdit()
le.setObjectName("host")
le.setText("Host")
pb = QPushButton()
pb.setObjectName("connect")
pb.setText("Connect")
layout.addWidget(le)
layout.addWidget(pb)
self.setLayout(layout)
self.connect(pb, SIGNAL("clicked()"),self.button_click)
self.setWindowTitle("Learning")
def button_click(self):
#i want the text in lineedit with objectname
#'host' in a string say 'shost'. when the user click
# the pushbutton with name connect.How do i do it?
# I tried and failed. How to implement this function?
app = QApplication(sys.argv)
form = Form()
form.show()
app.exec_()
Comment puis-je implémenter la fonction "button_click"? Je viens de commencer avec pyQt!
Vous obtiendrez plus facilement une réponse si vous postez un extrait de code qui fonctionne réellement. – brianz