2017-12-03 5 views
1

Ich versuche, Verknüpfungen zu meinem Editor zu implementieren, aber ich hatte bisher keinen Erfolg.Wie Sie QScintilla-Shortcuts zuweisen

Ich möchte einige der Standard-QScintilla-Verknüpfungen überschreiben. Ich habe dieses answer gelesen, aber ich bin nicht sicher, ob dies hilft, mein Problem zu lösen.

Ich habe auch die Scintilla (SCI_ASSIGNCMDKEY) Dokumentation gelesen, aber ich weiß nicht, wie ich es auf eine pythonische Weise verwenden soll.

es klar zu machen:

  1. ich die qscintilla außer Kraft setzen möchten, dass die Verknüpfung Strg + L und meine benutzerdefinierten Lösung verwenden (ordnen Sie es einer meiner Funktionen).

  2. Ich möchte den Befehl SCI_LINEDELETE der Verknüpfung Ctrl + D zuweisen.

Das ist meine Idee:

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_()) 
+0

Code anzeigen. – eyllanesc

Antwort

1

qscintilla bietet bereits die QsciCommandSet und QsciCommand Klassen für Verknüpfungen für den internen Editor Befehle Handhabung. Sie können auch QShortcut verwenden, um Verknüpfungen für Ihre eigenen Methoden zu erstellen.

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') 
0

, wenn Sie eine Symbolleiste in Ihrem qscintilla verwenden, ist Aktion Verknüpfungen als followeded

self.toolBar.newAction = QtWidgets.QAction(QtGui.QIcon(":/ico/new.png"),"New",self.toolBar) 
self.toolBar.newAction.setStatusTip("Clear TextBox or make new document.") 
self.toolBar.newAction.setShortcut("Ctrl+N") 
self.toolBar.newAction.triggered.connect(self.newfile) 

    #actions 
self.toolBar.addAction(self.toolBar.newAction) 
self.toolBar.addSeparator() 
Verwandte Themen