source: trunk/doc/html/focus.html@ 190

Last change on this file since 190 was 190, checked in by rudi, 14 years ago

reference documentation added

File size: 8.7 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/doc/focus.doc:36 -->
3<html>
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
6<title>Keyboard Focus Overview</title>
7<style type="text/css"><!--
8fn { margin-left: 1cm; text-indent: -1cm; }
9a:link { color: #004faf; text-decoration: none }
10a:visited { color: #672967; text-decoration: none }
11body { background: #ffffff; color: black; }
12--></style>
13</head>
14<body>
15
16<table border="0" cellpadding="0" cellspacing="0" width="100%">
17<tr bgcolor="#E5E5E5">
18<td valign=center>
19 <a href="index.html">
20<font color="#004faf">Home</font></a>
21 | <a href="classes.html">
22<font color="#004faf">All&nbsp;Classes</font></a>
23 | <a href="mainclasses.html">
24<font color="#004faf">Main&nbsp;Classes</font></a>
25 | <a href="annotated.html">
26<font color="#004faf">Annotated</font></a>
27 | <a href="groups.html">
28<font color="#004faf">Grouped&nbsp;Classes</font></a>
29 | <a href="functions.html">
30<font color="#004faf">Functions</font></a>
31</td>
32<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>Keyboard Focus Overview</h1>
33
34
35
36<p> <!-- index keyboard focus --><a name="keyboard-focus"></a>
37<p> Qt's widgets handle keyboard focus in the ways that have become
38customary in GUIs.
39<p> The basic issue is that the user's keystrokes can be directed at any
40of several windows on the screen, and any of several widgets inside
41the intended window. When the user presses a key, they expect it to go
42to the right place, and the software must try to meet this
43expectation. The system must determine which application the keystroke
44is directed at, which window within that application, and which widget
45within that window.
46<p> <h2> Focus motion
47</h2>
48<a name="1"></a><p> The customs which have evolved for directing keyboard focus to a
49particular widget are these:
50<ol type=1>
51<p> <li> The user presses Tab (or Shift+Tab) (or sometimes Enter).
52<p> <li> The user clicks a widget.
53<p> <li> The user presses a keyboard shortcut.
54<p> <li> The user uses the mouse wheel.
55<p> <li> The user moves the focus to a window, and the application must
56determine which widget within the window should get the focus.
57<p> </ol>
58<p> Each of these motion mechanisms is different, and different types of
59widgets receive focus in only some of them. We'll cover each of them
60in turn.
61<p> <h3> Tab or Shift+Tab.
62</h3>
63<a name="1-1"></a><p> Pressing Tab is by far the most common way to move focus using the
64keyboard. Sometimes in data-entry applications Enter does the same as
65Tab. We will ignore that for the moment.
66<p> Pressing Tab, in all window systems in common use today, moves the
67keyboard focus to the next widget in a circular per-window list. Tab
68moves focus along the circular list in one direction, Shift+Tab in the
69other. The order in which Tab presses move from widget to widget is
70called the tab order.
71<p> In Qt, this list is kept in the <a href="qfocusdata.html">QFocusData</a> class. There is one
72<a href="qfocusdata.html">QFocusData</a> object per window, and widgets automatically append
73themselves to the end of it when <a href="qwidget.html#setFocusPolicy">QWidget::setFocusPolicy</a>() is
74called with an appropriate <a href="qwidget.html#FocusPolicy-enum">QWidget::FocusPolicy</a>. You can customize
75the tab order using <a href="qwidget.html#setTabOrder">QWidget::setTabOrder</a>(). (If you don't, Tab
76generally moves focus in the order of widget construction.) <a href="designer-manual.html">Qt Designer</a> provides a means of visually
77changing the tab order.
78<p> Since pressing Tab is so common, most widgets that can have focus
79should support tab focus. The major exception is widgets that are
80rarely used, and where there is some keyboard accelerator or error
81handler that moves the focus.
82<p> For example, in a data entry dialog, there might be a field that is
83only necessary in one per cent of all cases. In such a dialog, Tab
84could skip this field, and the dialog could use one of these
85mechanisms:
86<p> <ol type=1>
87<p> <li> If the program can determine whether the field is needed, it can
88move focus there when the user finishes entry and presses OK, or when
89the user presses Enter after finishing the other fields. Alternately,
90include the field in the tab order but disable it. Enable it if it
91becomes appropriate in view of what the user has set in the other
92fields.
93<p> <li> The label for the field can include a keyboard shortcut that moves
94focus to this field.
95<p> </ol>
96<p> Another exception to Tab support is text-entry widgets that must
97support the insertion of tabs; almost all text editors fall into this
98class. Qt treats Control+Tab as Tab and Control+Shift+Tab as
99Shift+Tab, and such widgets can reimplement <a href="qwidget.html#event">QWidget::event</a>() and
100handle Tab before calling <a href="qwidget.html#event">QWidget::event</a>() to get normal processing of
101all other keys. However, since some systems use Control+Tab for other
102purposes, and many users aren't aware of Control+Tab anyway, this
103isn't a complete solution.
104<p> <h3> The user clicks a widget.
105</h3>
106<a name="1-2"></a><p> This is perhaps even more common than pressing Tab on computers with a
107mouse or other pointing device.
108<p> Clicking to move the focus is slightly more powerful than Tab. While
109it moves the focus <em>to</em> a widget, for editor widgets it also moves
110the text cursor (the widget's internal focus) to the spot where the
111mouse is clicked.
112<p> Since it is so common and people are used to it, it's a good idea to
113support it for most widgets. However, there is also an important
114reason to avoid it: you may not want to remove focus from the widget
115where it was.
116<p> For example, in a word processor, when the user clicks the 'B' (bold)
117tool button, what should happen to the keyboard focus? Should it
118remain where it was, almost certainly in the editing widget, or should
119it move to the 'B' button?
120<p> We advise supporting click-to-focus for widgets that support text
121entry, and to avoid it for most widgets where a mouse click has a
122different effect. (For buttons, we also recommend adding a keyboard
123shortcut: <a href="qbutton.html">QButton</a> and its subclasses make this very easy.)
124<p> In Qt, only the <a href="qwidget.html#setFocusPolicy">QWidget::setFocusPolicy</a>() function affects
125click-to-focus.
126<p> <h3> The user presses a keyboard shortcut.
127</h3>
128<a name="1-3"></a><p> It's not unusual for keyboard shortcuts to move the focus. This can
129happen implicitly by opening modal dialogs, but also explicitly using
130focus accelerators such as those provided by <a href="qlabel.html#setBuddy">QLabel::setBuddy</a>(), <a href="qgroupbox.html">QGroupBox</a> and <a href="qtabbar.html">QTabBar</a>.
131<p> We advise supporting shortcut focus for all widgets that the user may
132want to jump to. For example, a tab dialog can have keyboard shortcuts
133for each of its pages, so the user can press e.g. Alt+P to step to the
134<u>P</u>rinting page. But don't overdo this: there are only a few
135keys, and it's also important to provide keyboard shortcuts for
136commands. Alt+P is also used for Paste, Play, Print and Print Here in
137the <a href="accelerators.html">standard list of shortcuts</a>, for
138example.
139<p> <h3> The user uses the mouse wheel.
140</h3>
141<a name="1-4"></a><p> On Microsoft Windows, mouse wheel usage is always handled by the
142widget that has keyboard focus. On Mac OS X and X11, it's handled by
143the widget that gets other mouse events.
144<p> The way Qt handles this platform difference is by letting widgets move
145the keyboard focus when the wheel is used. With the right focus policy
146on each widget, applications can work idiomatically correctly on
147Windows, Mac OS X, and X11.
148<p> <h3> The user moves the focus to this window.
149</h3>
150<a name="1-5"></a><p> In this situation the application must determine which widget within
151the window should receive the focus.
152<p> This can be simple: if the focus has been in this window before, then
153the last widget to have focus should regain it. Qt does this
154automatically.
155<p> If focus has never been in this window before and you know where focus
156should start out, call <a href="qwidget.html#setFocus">QWidget::setFocus</a>() on the widget which
157should receive focus before you <a href="qwidget.html#show">QWidget::show</a>() it. If you don't,
158Qt will pick a suitable widget.
159<p>
160<!-- eof -->
161<p><address><hr><div align=center>
162<table width=100% cellspacing=0 border=0><tr>
163<td>Copyright &copy; 2007
164<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
165<td align=right><div align=right>Qt 3.3.8</div>
166</table></div></address></body>
167</html>
Note: See TracBrowser for help on using the repository browser.