Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. Reimplement QPlainText’s focusInEvent in another source file ,how to ?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Language Bindings
2 Posts 2 Posters 1.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    redstoneleo
    wrote on last edited by
    #1

    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 .

    1 Reply Last reply
    0
    • jazzycamelJ Offline
      jazzycamelJ Offline
      jazzycamel
      wrote on last edited by
      #2

      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.

      For the avoidance of doubt:

      1. All my code samples (C++ or Python) are tested before posting
      2. As of 23/03/20, my Python code is formatted to PEP-8 standards using black from the PSF (https://github.com/psf/black)
      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved