GUI 对话框的键盘控制 - 默认按钮是否应该随焦点变化?
在 GUI 对话框中,大多数应用程序都提供键盘控制,如下所示:
- Enter 键 - 按默认按钮。 (默认值通常用粗体按钮边框表示。)
- Esc 键 - 按取消或关闭按钮。
- 空格键 - 按下当前具有键盘焦点的小部件。
- Tab 键 - 将焦点移至下一个小部件。
问题是,当键盘焦点位于按钮小部件上时,是否应该将默认按钮更改为具有焦点的按钮?
我发现这种行为存在一些问题:
- 重绘按钮的显示噪音取消了原始默认按钮的轮廓,并将焦点下的按钮重新加粗为新的默认按钮。
- 空格键现在与 Enter 键有些多余。
- 现在没有键盘加速器可以获取正常的默认按钮(通常是“确定”按钮)。
然而,似乎趋势已经朝这个方向发展,即通过焦点更改到另一个按钮来更改默认按钮。与早期 GUI 的背离的理由是什么?鉴于无法按下原始默认按钮,它似乎提供的功能较少。人们是否发现原来的模型太复杂,用户无法理解?我认为对话框的键盘控制对于高级用户来说是一项任务,他们可以毫无困难地理解模型,并且更喜欢始终使用当前按钮(空格)和原始默认按钮(Enter)的加速器。
请注意,Qt for one 支持更改:QPushButton 的 autoDefault 属性负责更改默认按钮的行为。默认情况下其值为 true。因此,您必须采取额外的操作将所有按钮设置为 false,以防止它们在获得焦点时成为默认按钮。
In GUI dialogs, most applications provide for keyboard control as follows:
- Enter key - presses the default button. (Default is usually indicated with a bold button border.)
- Esc key - presses the Cancel or close button.
- Space key - presses widget that currently has keyboard focus.
- Tab key - advances focus to next widget.
Question is, when keyboard focus is on a widget that is a button, should the default button be changed to be the one with focus?
I see some issues with this behavior:
- The display noise of redrawing buttons to unbold the outline of original default button and rebold the button under focus as being new default.
- The Space key is now somewhat redundant with Enter key.
- There is no keyboard accelerator to get the normal default button now (Usually the OK button).
However, it seems the trend has been in this direction to change the default button with focus change to another button. What is the rationale for this departure from the early GUIs? It would seem to provide less functionality given there is no way to press the original default button. Did people find that the original model was too complicated for users to understand? I would think keyboard control of dialogs would be a task for advanced users who would have no trouble understanding the model and prefer to have accelerator for current button (Space) and original default button (Enter) at all times.
Note that Qt for one is supporting the change: QPushButton's autoDefault property is responsible for the behavior of changing the default button. By default its value is true. Therefore, you must take extra action to set it to false for all buttons, to prevent them from becoming the default button when focused.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这不是“与早期 GUI 的背离”,至少不是“早期 GUI”,如果您指的是 Windows 1.0。您所描述的行为从一开始就是这样。
当按下 Enter 键时,焦点按钮始终会被“按下”。默认按钮仅在以下两种情况下触发:
ES_WANTRETURN
样式标志的单行文本框)。著名的 Win32 博主 Raymond Chen 有一篇文章解释了这种行为(特别关注最后引用的两段):
This is not a "departure from the early GUIs", at least not if by "early GUIs", you mean Windows 1.0. The behavior that you describe has been this way since the beginning.
The focused button is always "pushed" when the Enter key is pressed. The default button is only triggered in the following two situations:
ES_WANTRETURN
style flag set).The famous Win32 blogger Raymond Chen has a post explaining this behavior (focus specifically on the last two quoted paragraphs):
我期望的行为是:
2.1 我按 Enter - 该事件应该传递到聚焦的小部件。 无需更改默认按钮 - 只需将事件传递给聚焦的小部件即可。
2.2 我按退出键。在这种情况下,一切都应该回到窗口创建后的状态。
注:
The behavior that I would expect is:
2.1 I press enter - this event should be delivered to the focused widget. There's no need to change the default button - simply hand the event to the focused widget.
2.2 I press escape. In this case, everything should go back to the state after the window is created.
Notes: