当前位置: 首页 > news >正文

pyqt5-自定义文本域1

快捷键支持:

CTRL+鼠标滚轮实现字体大小调整

支持复制当前行

剪切当前行

# 多行文本框
class TextEdit(QTextEdit):def __init__(self, parent=None):super().__init__(parent)self.setStyleSheet("background-color: #262626;color: #d0d0d0;")self.setFont(standard_font)  # 设置标准字体# Ctrl+鼠标滚轮调整字体大小def wheelEvent(self, event):# 捕捉鼠标滚轮事件modifiers = QApplication.keyboardModifiers()if modifiers == Qt.ControlModifier:# 如果按下了 Ctrl 键delta = event.angleDelta().y()font = self.font()# 根据滚轮方向调整字体大小if delta > 0:font.setPointSize(font.pointSize() + 1)else:font.setPointSize(font.pointSize() - 1)self.setFont(font)else:# 如果没有按下 Ctrl 键,则使用默认滚轮事件处理super().wheelEvent(event)# Ctrl+X,Ctrl+Cdef keyPressEvent(self, event):if event.modifiers() == Qt.ControlModifier and event.key() == Qt.Key_X:if self.textCursor().hasSelection():# If there is selected text, cut the selectionsuper().keyPressEvent(event)else:# If no text is selected, cut the entire lineself.cut_current_line()elif event.modifiers() == Qt.ControlModifier and event.key() == Qt.Key_C:if self.textCursor().hasSelection():# If there is selected text, cut the selectionsuper().keyPressEvent(event)else:# If no text is selected, cut the entire lineself.copy_current_line()else:super().keyPressEvent(event)# 剪切当前行内容def cut_current_line(self):cursor = self.textCursor()cursor.movePosition(QTextCursor.StartOfLine)cursor.movePosition(QTextCursor.EndOfLine, QTextCursor.KeepAnchor)self.setTextCursor(cursor)self.cut()# 复制当前行内容def copy_current_line(self):cursor = self.textCursor()cursor.movePosition(QTextCursor.StartOfLine)cursor.movePosition(QTextCursor.EndOfLine, QTextCursor.KeepAnchor)self.setTextCursor(cursor)self.copy()

http://www.lryc.cn/news/152619.html

相关文章:

  • Go实现LogCollect:海量日志收集系统【上篇——LogAgent实现】
  • MySQL (1)
  • MR混合现实汽车维修情景实训教学演示
  • ChatGPT在航空航天工程和太空探索中的潜在应用如何?
  • 算法基础第三章
  • ElementUI浅尝辄止20:Pagination 分页
  • Docker从认识到实践再到底层原理(二-1)|容器技术发展史+虚拟化容器概念和简介
  • 什么是大模型?1750亿、700GB的GPT大模型大在哪?
  • 剑指 Offer 10- II. 青蛙跳台阶问题
  • oracle10和11功能说明比较
  • golang-bufio 缓冲写
  • Windows修改电脑DNS
  • Linux驱动之Linux自带的LED灯驱动
  • C盘清理 “ProgramData\Microsoft\Search“ 文件夹过大
  • 深入了解字符串处理算法与文本操作技巧
  • Python爬虫:打开盈利大门的利器
  • 17.CSS发光按钮悬停特效
  • CSS中如何实现弹性盒子布局(Flexbox)的换行和排序功能?
  • spark底层为什么选择使用scala语言开发
  • 基于RabbitMQ的模拟消息队列之三——硬盘数据管理
  • DHorse v1.3.2 发布,基于 k8s 的发布平台
  • 在vue.config.js中配置文件路径代理名
  • 深度学习优化算法相关文章
  • echarts自定义Y轴刻度及其颜色
  • 【云原生进阶之PaaS中间件】第一章Redis-1.3Redis配置
  • C++ 动态内存
  • swagger 接口测试,用 python 写自动化时该如何处理?
  • QT使用QXlsx实现Excel图片与图表操作 QT基础入门【Excel的操作】
  • 【Python常用函数】一文让你彻底掌握Python中的numpy.clip函数
  • Matlab(GUI程式设计)