• <i id='hDKhG'><tr id='hDKhG'><dt id='hDKhG'><q id='hDKhG'><span id='hDKhG'><b id='hDKhG'><form id='hDKhG'><ins id='hDKhG'></ins><ul id='hDKhG'></ul><sub id='hDKhG'></sub></form><legend id='hDKhG'></legend><bdo id='hDKhG'><pre id='hDKhG'><center id='hDKhG'></center></pre></bdo></b><th id='hDKhG'></th></span></q></dt></tr></i><div id='hDKhG'><tfoot id='hDKhG'></tfoot><dl id='hDKhG'><fieldset id='hDKhG'></fieldset></dl></div>
    <legend id='hDKhG'><style id='hDKhG'><dir id='hDKhG'><q id='hDKhG'></q></dir></style></legend>
    • <bdo id='hDKhG'></bdo><ul id='hDKhG'></ul>

      <tfoot id='hDKhG'></tfoot>
    1. <small id='hDKhG'></small><noframes id='hDKhG'>

      1. 如何在 PyQT5 对话窗口中记录按下的组合键

        时间:2023-08-04
        • <bdo id='sF0ZV'></bdo><ul id='sF0ZV'></ul>
          <tfoot id='sF0ZV'></tfoot>
            <tbody id='sF0ZV'></tbody>
          <legend id='sF0ZV'><style id='sF0ZV'><dir id='sF0ZV'><q id='sF0ZV'></q></dir></style></legend>

            <small id='sF0ZV'></small><noframes id='sF0ZV'>

                  <i id='sF0ZV'><tr id='sF0ZV'><dt id='sF0ZV'><q id='sF0ZV'><span id='sF0ZV'><b id='sF0ZV'><form id='sF0ZV'><ins id='sF0ZV'></ins><ul id='sF0ZV'></ul><sub id='sF0ZV'></sub></form><legend id='sF0ZV'></legend><bdo id='sF0ZV'><pre id='sF0ZV'><center id='sF0ZV'></center></pre></bdo></b><th id='sF0ZV'></th></span></q></dt></tr></i><div id='sF0ZV'><tfoot id='sF0ZV'></tfoot><dl id='sF0ZV'><fieldset id='sF0ZV'></fieldset></dl></div>

                • 本文介绍了如何在 PyQT5 对话窗口中记录按下的组合键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我从主窗口打开对话框,通过夹住键,我在行中填入它们的名称.问题是我不明白你需要在哪里循环检查所有键的状态.也许还有另一种方法可以按下按键?或者哪里需要监听,让对话框不挂起,字符串更新.

                  I open the dialog from the main window, where by clamping the keys, I fill the line with their names. The problem is that I can not understand where you need to do a cycle of checking all the keys on their state. Maybe there is another way to get the keys pressed? Or where you need to listen to the clamping so that the dialog box does not hang and the string is updated.

                  MainWindow:
                      def showBindings(self, param):
                          from dialogs import KeyBindingsDialog
                          self.dialog = KeyBindingsDialog()
                          self.dialog.show()
                  
                  Dialog:
                  class KeyBindingsDialog(QtWidgets.QDialog):
                      def __init__(self, parent=None):
                          super(KeyBindingsDialog, self).__init__(parent)
                          self.ui = KeyBindings()
                          self.ui.setupUi(self)
                  

                  推荐答案

                  使用QKeySequenceEdit:

                  Use QKeySequence

                  from PyQt5 import QtCore, QtGui, QtWidgets
                  
                  class KeySequenceEdit(QtWidgets.QKeySequenceEdit):
                      def keyPressEvent(self, event):
                          super(KeySequenceEdit, self).keyPressEvent(event)
                          seq_string = self.keySequence().toString(QtGui.QKeySequence.NativeText)
                          if seq_string:
                              last_seq = seq_string.split(",")[-1].strip()
                              le = self.findChild(QtWidgets.QLineEdit, "qt_keysequenceedit_lineedit")
                              self.setKeySequence(QtGui.QKeySequence(last_seq))
                              le.setText(last_seq)
                              self.editingFinished.emit()
                  
                  
                  class Widget(QtWidgets.QWidget):
                      def __init__(self, parent=None):
                          super(Widget, self).__init__(parent)
                          self._keysequenceedit = KeySequenceEdit(editingFinished=self.on_editingFinished)
                          button = QtWidgets.QPushButton("clear", clicked=self._keysequenceedit.clear)
                          hlay = QtWidgets.QHBoxLayout(self)
                          hlay.addWidget(self._keysequenceedit)
                          hlay.addWidget(button)
                  
                      @QtCore.pyqtSlot()
                      def on_editingFinished(self):
                          sequence = self._keysequenceedit.keySequence()
                          seq_string = sequence.toString(QtGui.QKeySequence.NativeText)
                          print("sequence: ", seq_string)
                  
                  if __name__ == '__main__':
                      import sys 
                      app = QtWidgets.QApplication(sys.argv)
                      w = Widget()
                      w.show()
                      sys.exit(app.exec_())
                  

                  这篇关于如何在 PyQT5 对话窗口中记录按下的组合键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何从 qdateEdit 获取用户输入并从 postgres 的数据 下一篇:QMouseEvent' 对象没有属性 'pos'

                  相关文章

                  最新文章

                  <small id='7Pki8'></small><noframes id='7Pki8'>

                • <i id='7Pki8'><tr id='7Pki8'><dt id='7Pki8'><q id='7Pki8'><span id='7Pki8'><b id='7Pki8'><form id='7Pki8'><ins id='7Pki8'></ins><ul id='7Pki8'></ul><sub id='7Pki8'></sub></form><legend id='7Pki8'></legend><bdo id='7Pki8'><pre id='7Pki8'><center id='7Pki8'></center></pre></bdo></b><th id='7Pki8'></th></span></q></dt></tr></i><div id='7Pki8'><tfoot id='7Pki8'></tfoot><dl id='7Pki8'><fieldset id='7Pki8'></fieldset></dl></div>

                  • <bdo id='7Pki8'></bdo><ul id='7Pki8'></ul>

                    1. <tfoot id='7Pki8'></tfoot>
                      <legend id='7Pki8'><style id='7Pki8'><dir id='7Pki8'><q id='7Pki8'></q></dir></style></legend>