Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第五章qt_QSqlQueryModel快捷键不好用 #4

Open
fxbird opened this issue May 7, 2024 · 1 comment
Open

第五章qt_QSqlQueryModel快捷键不好用 #4

fxbird opened this issue May 7, 2024 · 1 comment

Comments

@fxbird
Copy link

fxbird commented May 7, 2024

我发现凡是用到了快捷键的例子没一个好用的
py version: 3.11.9
OS:win11

@sunshe35
Copy link
Owner

sunshe35 commented May 7, 2024

你好,这个应该是pyqt的问题。 以Chapter05/qt_QSqlQueryModel.py为例。
代码

menu.addAction(QIcon("images/right.png"), '后一页', QKeySequence(Qt.Modifier.CTRL | Qt.Key.Key_N), self.onNextButtonClick)

next = QAction(QIcon("images/right.png"),'后一页',self)
next.setShortcut(QKeySequence(Qt.Modifier.CTRL|Qt.Key.Key_N))
next.triggered.connect(self.onNextButtonClick)
menu.addAction(next)

是等价的,而后者在这个案例中快捷键也无效,但是从菜单中点击的时候,确实触发了onNextButtonClick方法。

参考案例Chapter04/qt_QShortcut.py,后者的快捷键绑定是没问题的。
也就是说,我们正确设置了快捷键绑定,但是没有成功触发,这应该是pyqt的bug.

解决方法可以参考Chapter04/qt_QShortcut.py案例,使用自定义shortcut, 再次绑定一次快捷键:

menu.addAction(QIcon("images/right.png"), '后一页', QKeySequence(Qt.Modifier.CTRL | Qt.Key.Key_N), self.onNextButtonClick)
short_next = QShortcut(QKeySequence("Ctrl+N"),self)
short_next.activated.connect(self.onNextButtonClick)

在很早的pyqt6.2版本,shortcut参数要放在slot参数之后,现在要放在slot参数之前,不知道是不是这个变化导致的快捷键失效。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants