Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Clear QTextEdit widget on mouse click in text entry box
Forum Updated to NodeBB v4.3 + New Features

Clear QTextEdit widget on mouse click in text entry box

Scheduled Pinned Locked Moved Unsolved Qt for Python
2 Posts 1 Posters 2.1k Views
  • 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.
  • K Offline
    K Offline
    kyouma
    wrote on last edited by
    #1

    Hi all, I'm using PyQt5 and I'm trying to get the QTextBox to clear itself when it is clicked with mouse (or tabbed into, for that matter). I am not sure how to accomplish this but I was looking at the method mousePressEvent(), but I guess this would only cover the mouse press instead of having tabbed into it as well

    import sys
    import parser
    from PyQt5.QtWidgets import QDialog, QApplication
    from PyQt5.Qt import QEvent, QMouseEvent, QWidget
    
    from MainWindow import *
    
    
    class MainWindow(QtWidgets.QMainWindow):
    
        def __init__(self):
            super().__init__()
            self.ui = Ui_MainWindow()
            self.ui.setupUi(self)
            self.ui.pushButtonEnter.clicked.connect(self.dispmessage)
            self.ui.lineEditAnswer.setText("Enter something here")
            self.ui.lineEditAnswer.mousePressEvent(self)
            self.ui.labelVocab.setText("null")
            self.show()
    
        def dispmessage(self):
            self.ui.labelVocab.setText(self.ui.lineEditAnswer.text())
    
    if __name__ == "__main__":
        deck = parser.parser()
        app = QApplication(sys.argv)
        win = MainWindow()
        win.show()
        sys.exit(app.exec_())```
    1 Reply Last reply
    0
    • K Offline
      K Offline
      kyouma
      wrote on last edited by
      #2

      I solved my own problem. I wanted to make it so that I had "Enter your answer" in the text input until the user actually entered something.. BUT you can just select this in QDesigner QTextEdit properties and select 'placeholderText' to properly show a greyed out message prior to input.

      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