Reimplement QPlainText’s focusInEvent in another source file ,how to ?



  • The UI is as following

    The UI is as following
    http://img.my.csdn.net/uploads/201211/07/1352267120_2257.jpg

    I saved the form as a file named re.ui
    Then I convert it into Python script named ui_re.py
    Third ,I create the source file with the name
    callFirstApp.pyw and import the ui_re.py to it

    The code in the callFirstApp.pyw is as shown here:
    @

    import sys
    from PySide.QtGui import *
    from ui_re import *

    class MainWindow(QMainWindow, Ui_MainWindow):
    def init(self, parent=None):
    super(MainWindow, self).init(parent)
    self.setupUi(self)
    self.plainTextEdit.setPlainText("Type code here...")

    if name == 'main':
    app =QApplication(sys.argv)
    frame = MainWindow()
    frame.show()
    app.exec_()
    @
    I want to reimplement the QPlainText’s focusInEvent in this file ,my code is as following
    (means let the default text "Type code here..." disappear when focus in the QTextEdit’s editable area)

    @
    def focusInEvent(self, event):
    self.clear()
    QPlainTextEdit.focusInEvent(self, event)
    @
    But I don’t know how to add the code to the file correctly ?
    Thanks in advance .



  • I'm not an expert in the use of Designer but AFAIK, you can't. You can write a widget with the functionality you want and expose it to designer (Put a normal QTextEdit in you UI form and then use the promote to... option, I've only done this in C++).

    IMHO, Designer and forms are only good for simple UI's where you don't want to modify standard behaviors, just connect to signals and slots and call methods on the created objects. I hardly ever use it preferring to layout all my UI's in pure python (or C++) as you have much finer control and better access to the objects you're creating. As I say, this is only my opinion. In your case, it will probably be simpler and quicker to do this.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.