GUI 对话框的键盘控制 - 默认按钮是否应该随焦点变化?

发布于 2024-11-24 23:39:13 字数 706 浏览 2 评论 0原文

在 GUI 对话框中,大多数应用程序都提供键盘控制,如下所示:

  1. Enter 键 - 按默认按钮。 (默认值通常用粗体按钮边框表示。)
  2. Esc 键 - 按取消或关闭按钮。
  3. 空格键 - 按下当前具有键盘焦点的小部件。
  4. Tab 键 - 将焦点移至下一个小部件。

问题是,当键盘焦点位于按钮小部件上时,是否应该将默认按钮更改为具有焦点的按钮?

我发现这种行为存在一些问题:

  1. 重绘按钮的显示噪音取消了原始默认按钮的轮廓,并将焦点下的按钮重新加粗为新的默认按钮。
  2. 空格键现在与 Enter 键有些多余。
  3. 现在没有键盘加速器可以获取正常的默认按钮(通常是“确定”按钮)。

然而,似乎趋势已经朝这个方向发展,即通过焦点更改到另一个按钮来更改默认按钮。与早期 GUI 的背离的理由是什么?鉴于无法按下原始默认按钮,它似乎提供的功能较少。人们是否发现原来的模型太复杂,用户无法理解?我认为对话框的键盘控制对于高级用户来说是一项任务,他们可以毫无困难地理解模型,并且更喜欢始终使用当前按钮(空格)和原始默认按钮(Enter)的加速器。

请注意,Qt for one 支持更改:QPushButton 的 autoDefault 属性负责更改默认按钮的行为。默认情况下其值为 true。因此,您必须采取额外的操作将所有按钮设置为 false,以防止它们在获得焦点时成为默认按钮。

In GUI dialogs, most applications provide for keyboard control as follows:

  1. Enter key - presses the default button. (Default is usually indicated with a bold button border.)
  2. Esc key - presses the Cancel or close button.
  3. Space key - presses widget that currently has keyboard focus.
  4. 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:

  1. The display noise of redrawing buttons to unbold the outline of original default button and rebold the button under focus as being new default.
  2. The Space key is now somewhat redundant with Enter key.
  3. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

花开雨落又逢春i 2024-12-01 23:39:13

不是“与早期 GUI 的背离”,至少不是“早期 GUI”,如果您指的是 Windows 1.0。您所描述的行为从一开始就是这样。

当按下 Enter 键时,焦点按钮始终会被“按下”。默认按钮仅在以下两种情况下触发:

  • 默认按钮具有焦点(默认情况下确实如此),或者
  • 焦点位于不处理 Enter 按键的控件上(例如静态控件,或没有设置 ES_WANTRETURN 样式标志的单行文本框)。

著名的 Win32 博主 Raymond Chen 有一篇文章解释了这种行为(特别关注最后引用的两段):

对话框保留了“默认按钮”(始终是按钮)的概念。默认按钮通常采用独特的外观(粗轮廓或不同的颜色)绘制,并指示当您按 Enter 时对话框将执行什么操作。请注意,这与具有焦点的控件不同。

例如,从“开始”菜单打开“运行”对话框。请注意,“确定”按钮是默认按钮;它的外观与其他按钮不同。但重点是编辑控件。您的输入将转到编辑控件,直到您按 Enter;按 Enter 激活默认按钮,这样就可以了。

当您使用 Tab 键浏览对话框时,观察默认按钮会发生什么情况。当对话框将焦点移至某个按钮时,该按钮将成为新的默认按钮。但是,当对话框将焦点移至根本不是按钮的某个位置时,“确定”按钮将恢复其作为默认按钮的位置。

对话框管理器会记住最初创建对话框时哪个控件是默认按钮,并且当它将焦点移至非按钮时,它会将该原始按钮恢复为默认按钮。

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:

  • The default button has the focus (which it does by default), or
  • The focus is on a control that does not process Enter key presses (such as a static control, or a single-line textbox that does not have the 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):

A dialog box maintains the concept of a "default button" (which is always a pushbutton). The default button is typically drawn with a distinctive look (a heavy outline or a different color) and indicates what action the dialog box will take when you hit Enter. Note that this is not the same as the control that has the focus.

For example, open the Run dialog from the Start menu. Observe that the OK button is the default button; it has a different look from the other buttons. But focus is on the edit control. Your typing goes to the edit control, until you hit Enter; the Enter activates the default button, which is OK.

As you tab through the dialog, observe what happens to the default button. When the dialog box moves focus to a pushbutton, that pushbutton becomes the new default button. But when the dialog box moves focus to something that isn't a pushbutton at all, the OK button resumes its position as the default button.

The dialog manager remebers which control was the default button when the dialog was initially created, and when it moves focus to something that isn't a button, it restores that original button as the default button.

夜吻♂芭芘 2024-12-01 23:39:13

我期望的行为是:

  1. 如果我在窗口刚刚弹出时按 Enter,它应该按默认按钮
  2. 如果我按 Tab,我开始在小部件中导航。在这种情况下,有两个选项:

2.1 我按 Enter - 该事件应该传递到聚焦的小部件。 无需更改默认按钮 - 只需将事件传递给聚焦的小部件即可。

2.2 我按退出键。在这种情况下,一切都应该回到窗口创建后的状态。

注:

  • 我来自混合背景 - 我不知道我是在 Windows、Linux 还是移动操作系统中学到的!这正是我所期望的事情的发展方式。
  • 我不使用空格键(不知道它的功能)

The behavior that I would expect is:

  1. If I press enter when the window just pop up, it should press the default button
  2. If I press tab, I start navigating through the widgets. In this case there are two options:

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:

  • I come from a mixed background - I don't know if I learned this in windows, linux or Mobile OSes! This is just how I expect things to work out.
  • I don't use the space key (didn't know it's functionality)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文