- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试实现编辑器的快捷方式,但到目前为止还没有取得任何成功。
我想覆盖一些默认的 QScintilla 快捷键。我读过这篇answer ,但我不确定这是否有助于解决我的问题。
我还阅读了 Scintilla (SCI_ASSIGNCMDKEY
) 文档,但我不知道应该如何以 python 方式使用它。
明确一点:
我想覆盖 QScintilla 快捷键 Ctrl+L 并使用我的自定义解决方案(将其分配给我的函数之一)。
我想将命令 SCI_LINEDELETE
分配给快捷键 Ctrl+D。
这是我的想法:
from PyQt5.Qsci import QsciScintilla
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import sys
class mainWindow(QMainWindow):
def __init__(self, parent = None):
super(mainWindow, self).__init__(parent)
self.initUI()
def initUI(self):
self.center_window = centerWindow(parent=self)
self.setCentralWidget(self.center_window)
class centerWindow(QWidget):
def __init__(self, parent=None):
super(centerWindow, self).__init__(parent)
self.hhEditor_te = QsciScintilla()
vbox = QVBoxLayout(self)
vbox.addWidget(self.hhEditor_te)
self.setLayout(vbox)
# 1)
# assign a key binding to this function
# self.my_shortcut
# 2)
# assign a key binding to the QScintilla command
# SCI_LINEDELETE
def my_shortcut(self):
pass
# my custom shortcut function
if __name__ == '__main__':
app = QApplication.instance()
if app is None:
app = QApplication(sys.argv)
else:
print('QApplication instance already exists: %s' % str(app))
ex = mainWindow()
ex.setGeometry(0,100,1500,600)
ex.show()
sys.exit(app.exec_())
最佳答案
QScintilla 已提供 QsciCommandSet和 QsciCommand用于处理内部编辑器命令的快捷方式的类。您还可以使用QShortcut为您自己的方法创建快捷方式。
class centerWindow(QWidget):
def __init__(self, parent=None):
...
commands = self.hhEditor_te.standardCommands()
command = commands.boundTo(Qt.ControlModifier | Qt.Key_L)
if command is not None:
command.setKey(0) # clear the default
command = commands.boundTo(Qt.ControlModifier | Qt.Key_D)
if command is not None:
command.setKey(0) # clear the default
command = commands.find(QsciCommand.LineDelete)
if command is not None:
command.setKey(Qt.ControlModifier | Qt.Key_D)
shortcut = QShortcut(Qt.ControlModifier | Qt.Key_L, self.hhEditor_te)
shortcut.activated.connect(self.my_shortcut)
...
def my_shortcut(self):
print('Ctrl+L')
关于python - 如何分配 QScintilla 快捷键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47622714/
我想试用 QScintilla。所以我下载并安装了它,没问题。当我运行示例项目时,它说我缺少 QtCored4.dll,所以我将它复制到目录中,然后它说它还需要其他 dll,所以也复制了它们。 最后它
当我将 QsciScintilla 对象添加到主窗口时,水平滚动条处于事件状态并且超宽(大量明显的空白)。容易修复吗? 最佳答案 简单修复: sc.SendScintilla(sc.SCI_SETHS
我正在尝试为 QScintilla 创建一个基于 JavaScript 的自定义词法分析器。我已经弄清楚如何在词法分析器中添加关键字。但是,我不知道如何改变它们在输入时的外观,例如,当您输入单词 fu
我正在使用 C++ 开发源代码编辑器,使用 Qt5 和 QScintilla 作为框架。在这个项目中,我想连续显示文本光标的行和列(光标位置),所以我需要一个在移动文本光标时发出的信号。根据 QSci
考虑这个 mcve: import math import sys import textwrap import time from pathlib import Path from collecti
如果自动完成阈值设置为 1,我想在 html 文件的自动完成列表中显示所有属性和标签。我已经尝试使用此代码来使用 API,我在文件加载到新的 mdi child 后设置了此代码(子窗口)但它不工作:
我得到了这段简单的 mcve 代码: import sys import re from PyQt5 import QtGui, QtWidgets, QtCore from PyQt5.Qsci i
我得到了这个小 mcve 代码: import sys import re from PyQt5 import QtGui, QtWidgets, QtCore from PyQt5.QtCore i
我找到了这个演示 autocompletion-using-pyqt4-and-qscintilla 但是,有时会导致段错误。 这个演示是否正确? 最佳答案 要回答标题“如何使用 QScintilla
我正在尝试实现编辑器的快捷方式,但到目前为止还没有取得任何成功。 我想覆盖一些默认的 QScintilla 快捷键。我读过这篇answer ,但我不确定这是否有助于解决我的问题。 我还阅读了 Scin
我喜欢 PySide,并且已经使用了一段时间,但是在我目前正在编写的程序中,我需要一个高级代码编辑器。 我找到了 QScintilla ,但那是针对 PyQt 的。它与 PySide 兼容吗?如果兼容
我正在尝试在 QScintilla 中实现一个适用于多项选择的切换评论功能。不幸的是我不太清楚该怎么做,到目前为止我已经想出了这段代码: import sys import re import mat
考虑这个片段: import sys from PyQt5.Qsci import QsciScintilla from PyQt5.Qt import * if __name__ == '__mai
这里的最终目标是在 QScintilla 中实现基于缩进的代码折叠,类似于 SublimeText3 的方式。 首先,这里有一个小例子,说明如何使用 QScintilla 机制手动提供折叠: impo
我想防止在我的 QScintilla 小部件中编辑代码时触发应用程序键盘快捷键,就像普通的 QLineEdit 字段不会一样。 在下面的可执行示例代码中,不可能在 QScintilla 小部件中键入空
我正在努力告诉 QScitilla textEdit(我的 MainWindow 应用程序的主要小部件)接受在右键单击鼠标时显示个性化上下文菜单。 如果与 QScintilla 替代品一起使用,如果我
我最近一直在通过在我的 python 应用程序中实现 QsciLexerCustom 来创建我自己的 Progress 4GL 编辑器。但是在浏览 Qscintilla Source 时我注意到他们已
我正在尝试编写一个搜索框,其中包含查找/查找上一个/查找下一个以与 QScintilla textEditor 小部件进行交互。因此,我写了一些方法,一个用于突出显示所有匹配的单词然后选择第一次出现,
类似于这个问题:Creating and colorizing new constructs on a existing Scintilla lexer但我不想添加,而是想修改 pyqt4 中词法分析
我想让我的边距看起来像这样:- 到目前为止我已经这样做了:- 使用以下代码:- self.setMarginType(1,Qsci.QsciScintilla.NumberMargin) self.s
我是一名优秀的程序员,十分优秀!