V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2022-07-08 19:07:15 +08:00 · 1176 次点击
    这是一个创建于 655 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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 条回复    2022-07-14 23:29:13 +08:00
    llsquaer
        1
    llsquaer  
       2022-07-11 14:16:49 +08:00
    没记错的话..重写最好用类继承重写..

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

    组件的事件大多是继承至 QWidget 查下这个类的所有方法吧.
    junkun
        2
    junkun  
       2022-07-14 23:29:13 +08:00
    要手动调用基类的功能才行的,所以确实最好用继承。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1252 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 23:25 · PVG 07:25 · LAX 16:25 · JFK 19:25
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.