推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
ferencz
V2EX  ›  Python

pyqt5 textedit 重写点击事件后无法选中文本

  •  1
     
  •   ferencz · Jul 8, 2022 · 1751 views
    This topic created in 1430 days ago, the information mentioned may be changed or developed.
    import sys
    from PyQt5 import QtCore, QtWidgets
    
    def text_change():
        print("change ok")
    def text_click(event):
        print("clicked ok ")
    
    app = QtWidgets.QApplication(sys.argv)
    textEdit = QtWidgets.QTextEdit()
    textEdit.setGeometry(QtCore.QRect(30, 20, 351, 51))
    textEdit.setObjectName("textEdit")
    textEdit.mousePressEvent = text_click
    textEdit.textChanged.connect(text_change)
    textEdit.show()
    sys.exit(app.exec_())
    

    重写点击事件后,无法选中文本框中的文本 怎么解决呢大佬 是不是覆盖了选中文本的事件? 因为都有一个点击事件?感谢大佬

    2 replies    2022-07-14 23:29:13 +08:00
    llsquaer
        1
    llsquaer  
       Jul 11, 2022
    没记错的话..重写最好用类继承重写..

    你这个写法相当于修改了原来的鼠标事件函数..会导致使用这个鼠标事件的所有事情停止.

    组件的事件大多是继承至 QWidget 查下这个类的所有方法吧.
    junkun
        2
    junkun  
       Jul 14, 2022
    要手动调用基类的功能才行的,所以确实最好用继承。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   856 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 20:40 · PVG 04:40 · LAX 13:40 · JFK 16:40
    ♥ Do have faith in what you're doing.