[PyQt] Fwd: Use QTextEdit() clear slot

Simon Stockes simonstockes at gmail.com
Wed Jan 30 13:39:12 GMT 2008


Hi,

After sinuous ways I found a solution that work. It's not still   
clear in my mind but it works.

I had to add 'self.cleanButton.setAutoDefault(False)' because adding  
a 'self.cleanButton.setDefault(False)' does not work.

As the Qt assistant said, it depends of the GUI style .... A beat  
tedious, no ?


Although i receive no answer to my question, some questions came to me:

Was my question too evident ?

Too few people are reading this mailing-list ?

Were my sentences not very well express ?

No luck ?


Cheers, Simon.



Début du message réexpédié :

> De : Simon Stockes <simonstockes at gmail.com>
> Date : 21 janvier 2008 21:13:50 HNEC
> À : PyQt at riverbankcomputing.com
> Objet : Use QTextEdit() clear slot
>
> Hi All,
>
> It seems that  "cleanButton connect" stop to a new expression  
> evaluation in the following code ?
>
> 1/ If you comment this connection the program works again !!
>
> 2/ If you "reset" with the "cleanButton" something you wrote in the  
> QTextEdit, it cleans it !!
>
>
>
> Any track ?
>
>
> Simon
>
>
>
> CODE
> =====
>
>
> from __future__ import division
>
> import sys
> from math import *
> from PyQt4.QtCore import *
> from PyQt4.QtGui import *
>
>
> class Ui_MainWindow(QDialog):
>
>     def __init__(self, parent=None):
>         super(Ui_MainWindow, self).__init__(parent)
>         self.browser = QTextEdit()
>         self.lineedit = QLineEdit("Enter an expression anf press  
> Enter")
>         self.lineedit.selectAll()
>         self.cleanButton = QPushButton("Reset")
>         layout = QVBoxLayout()
>         layout.addWidget(self.browser)
>         layout.addWidget(self.lineedit)
>         layout.addWidget(self.cleanButton)
>         self.setLayout(layout)
>         self.lineedit.setFocus()
>         self.setWindowTitle("Calculator")
>
> #???????????????????????????????????????????
>
>         self.connect(self.cleanButton, SIGNAL("clicked()"),  
> self.clearForm)
>
>  #??????????????????????????????????????????
>
>     def clearForm(self):
>         self.browser.clear()
>
>
> class App(object):
>     """ Run Calculator's GUI, main controller class (MAIN  
> CONTROLER)"""
>
>     def __init__(self):
>         """ Creation of Calculator's GUI and connexion with user  
> events """
>
>         # Creation of the Calculator's GUI:
>         self.mainwindow = Ui_MainWindow()
>
>         self.mainwindow.connect(self.mainwindow.lineedit, SIGNAL 
> ("returnPressed()"),  self.updateUi)
>
>     def updateUi(self):
>         try:
>             text = unicode(self.mainwindow.lineedit.text())
>             self.mainwindow.browser.append("%s = <b>%s<b><br>" % 
> (text, eval(text)) )
>             self.mainwindow.lineedit.selectAll()
>         except:
>             self.mainwindow.browser.append(('<font color="red">%s  
> is wrong<font><br>' %text))
>             self.mainwindow.lineedit.selectAll()
>
>
> if __name__ == "__main__":
>     app = QApplication(sys.argv)
>
>     # init GUI
>     calc = App()
>
>     # display of GUI
>     calc.mainwindow.show()
>
>     app.exec_()
>
>
>
>
>




More information about the PyQt mailing list