📄 qaccel.3qt
字号:
'\" t.TH QAccel 3qt "11 October 2001" "Trolltech AS" \" -*- nroff -*-.\" Copyright 1992-2001 Trolltech AS. All rights reserved. See the.\" license file included in the distribution for a complete license.\" statement..\".ad l.nh.SH NAMEQAccel \- Handles keyboard accelerator and shortcut keys.PP\fC#include <qaccel.h>\fR.PPInherits QObject..PP.SS "Public Members".in +1c.ti -1c.BI "\fBQAccel\fR ( QWidget * parent, const char * name = 0 )".br.ti -1c.BI "\fBQAccel\fR ( QWidget * watch, QObject * parent, const char * name = 0 )".br.ti -1c.BI "\fB~QAccel\fR ()".br.ti -1c.BI "bool \fBisEnabled\fR () const".br.ti -1c.BI "void \fBsetEnabled\fR ( bool enable )".br.ti -1c.BI "uint \fBcount\fR () const".br.ti -1c.BI "int \fBinsertItem\fR ( const QKeySequence & key, int id = -1 )".br.ti -1c.BI "void \fBremoveItem\fR ( int id )".br.ti -1c.BI "void \fBclear\fR ()".br.ti -1c.BI "QKeySequence \fBkey\fR ( int id )".br.ti -1c.BI "int \fBfindKey\fR ( const QKeySequence & key ) const".br.ti -1c.BI "bool \fBisItemEnabled\fR ( int id ) const".br.ti -1c.BI "void \fBsetItemEnabled\fR ( int id, bool enable )".br.ti -1c.BI "bool \fBconnectItem\fR ( int id, const QObject * receiver, const char * member )".br.ti -1c.BI "bool \fBdisconnectItem\fR ( int id, const QObject * receiver, const char * member )".br.ti -1c.BI "void \fBrepairEventFilter\fR ()".br.ti -1c.BI "void \fBsetWhatsThis\fR ( int id, const QString & text )".br.ti -1c.BI "QString \fBwhatsThis\fR ( int id ) const".br.in -1c.SS "Signals".in +1c.ti -1c.BI "void \fBactivated\fR ( int id )".br.in -1c.SS "Static Public Members".in +1c.ti -1c.BI "QKeySequence \fBshortcutKey\fR ( const QString & str )".br.ti -1c.BI "QString keyToString ( QKeySequence k ) \fI(obsolete)\fR".br.ti -1c.BI "QKeySequence stringToKey ( const QString & s ) \fI(obsolete)\fR".br.in -1c.SS "Protected Members".in +1c.ti -1c.BI "virtual bool \fBeventFilter\fR ( QObject * o, QEvent * e )".br.in -1c.SH DESCRIPTIONThe QAccel class handles keyboard accelerator and shortcut keys..PPA keyboard accelerator triggers an action when a certain key combination is pressed. The accelerator handles all keyboard activity for all children of one top-level widget, so it is not affected by the keyboard focus..PPIn most cases, you will not need to use this class directly. Use the QAction class to create actions with accelerators that can be used in both menus and toolbars. If you're only interested in menus use QMenuData::insertItem() or QMenuData::setAccel() to make accelerators for operations that are also available on menus. Many widgets automatically generate accelerators, such as QButton, QGroupBox, QLabel (with QLabel::setBuddy()), QMenuBar and QTabBar. Example:.PP.nf.br QPushButton p( "&Exit", parent ); //automatic shortcut ALT+Key_E.br QPopupMenu *fileMenu = new fileMenu( parent );.br fileMenu->insertItem( "Undo", parent, SLOT(undo()), CTRL+Key_Z );.br.fi.PPA QAccel contains a list of accelerator items that can be manipulated using insertItem(), removeItem(), clear(), key() and findKey()..PPEach accelerator item consists of an identifier and a QKeySequence. A single key sequence consists of a keyboard code combined with modifiers (SHIFT, CTRL, ALT or UNICODE_ACCEL). For example, \fCCTRL + Key_P\fR could be a shortcut for printing a document. The key codes are listed in qnamespace.h. As an alternative, use UNICODE_ACCEL with the unicode code point of the character. For example, \fCUNICODE_ACCEL + 'A'\fR gives the same accelerator as Key_A..PPWhen an accelerator key is pressed, the accelerator sends out the signal activated() with a number that identifies this particular accelerator item. Accelerator items can also be individually connected, so that two different keys will activate two different slots (see connectItem() and disconnectItem())..PPUse setEnabled() to enable/disable all items in the accelerator, or setItemEnabled() to enable/disable individual items. An item is active only when the QAccel is enabled and the item itself is..PPThe function setWhatsThis() specifies a help text that appears when the user presses an accelerator key in What's This mode..PPA QAccel object handles key events to the QWidget::topLevelWidget() containing \fIparent\fR, and hence to any child widgets of that window. The accelerator will be deleted when \fIparent\fR is deleted, and will consume relevant key events until then..PPExample:.PP.nf.br QAccel *a = new QAccel( myWindow ); // create accels for myWindow.br a->connectItem( a->insertItem(Key_P+CTRL), // adds Ctrl+P accelerator.br myWindow, // connected to myWindow's.br SLOT(printDoc()) ); // printDoc() slot.br.fi.PPSee also QKeyEvent, QWidget::keyPressEvent(), QMenuData::setAccel(), QButton::accel, QLabel::setBuddy(), GUI Design Handbook: Keyboard Shortcuts and Miscellaneous Classes..SH MEMBER FUNCTION DOCUMENTATION.SH "QAccel::QAccel ( QWidget * parent, const char * name = 0 )"Constructs a QAccel object with parent \fIparent\fR and name \fIname\fR. The accelerator operates on \fIparent\fR..SH "QAccel::QAccel ( QWidget * watch, QObject * parent, const char * name = 0 )"Constructs a QAccel object that operates on \fIwatch\fR, but is a child of \fIparent\fR. The object is called \fIname\fR..PPThis constructor is not needed for normal application programming..SH "QAccel::~QAccel ()"Destroys the accelerator object and frees all allocated resources..SH "void QAccel::activated ( int id )\fC [signal]\fR"This signal is emitted when an accelerator key is pressed. \fIid\fR is a number that identifies this particular accelerator item..SH "void QAccel::clear ()"Removes all accelerator items..SH "bool QAccel::connectItem ( int id, const QObject * receiver, const char * member )"Connects the accelerator item \fIid\fR to the slot \fImember\fR of \fIreceiver\fR..PP.nf.br a->connectItem( 201, mainView, SLOT(quit()) );.br.fi.PPOf course, you can also send a signal as \fImember\fR..PPSee also disconnectItem()..PPExample: t14/gamebrd.cpp..SH "uint QAccel::count () const"Returns the number of accelerator items in this accelerator..SH "bool QAccel::disconnectItem ( int id, const QObject * receiver, const char * member )"Disconnects an accelerator item with id \fIid\fR from the function called \fImember\fR in the \fIreceiver\fR object..PPSee also connectItem()..SH "bool QAccel::eventFilter ( QObject * o, QEvent * e )\fC [virtual protected]\fR"Processes accelerator events intended for the top level widget. \fIe\fR is the event that occurred on object \fIo\fR..PPReimplemented from QObject..SH "int QAccel::findKey ( const QKeySequence & key ) const"Returns the identifier of the accelerator item with the key code \fIkey\fR, or -1 if the item cannot be found..SH "int QAccel::insertItem ( const QKeySequence & key, int id = -1 )"Inserts an accelerator item and returns the item's identifier..PP\fIkey\fR is a key code plus a combination of SHIFT, CTRL and ALT. \fIid\fR is the accelerator item id..PPIf \fIid\fR is negative, then the item will be assigned a unique negative identifier less than -1..PP.nf.br QAccel *a = new QAccel( myWindow ); // create accels for myWindow.br a->insertItem( Key_P + CTRL, 200 ); // Ctrl+P to print document.br a->insertItem( Key_X + ALT , 201 ); // Alt+X to quit.br a->insertItem( UNICODE_ACCEL + 'q', 202 ); // Unicode 'q' to quit.br a->insertItem( Key_D ); // gets a unique negative id < -1.br a->insertItem( Key_P + CTRL + SHIFT ); // gets a unique negative id < -1.br.fi.PPExample: t14/gamebrd.cpp..SH "bool QAccel::isEnabled () const"Returns TRUE if the accelerator is enabled, or FALSE if it is disabled..PPSee also setEnabled() and isItemEnabled()..SH "bool QAccel::isItemEnabled ( int id ) const"Returns TRUE if the accelerator item with the identifier \fIid\fR is enabled. Returns FALSE if the item is disabled or cannot be found..PPSee also setItemEnabled() and isEnabled()..SH "QKeySequence QAccel::key ( int id )"Returns the key code of the accelerator item with the identifier \fIid\fR, or zero if the id cannot be found..SH "QString QAccel::keyToString ( QKeySequence k )\fC [static]\fR"\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code..PPCreates an accelerator string for the key \fIk\fR. For instance CTRL+Key_O gives "Ctrl+O". The "Ctrl" etc. are translated (using QObject::tr()) in the "QAccel" scope..PPThe function is superfluous. Cast the QKeySequence \fIk\fR to a QString for the same effect..PPSee also stringToKey()..SH "void QAccel::removeItem ( int id )"Removes the accelerator item with the identifier \fIid\fR..SH "void QAccel::repairEventFilter ()"Makes sure that the accelerator is watching the correct event filter. This function is called automatically; you should not need to call it in application code..SH "void QAccel::setEnabled ( bool enable )"Enables the accelerator if \fIenable\fR is TRUE, or disables it if \fIenable\fR is FALSE..PPIndividual keys can also be enabled or disabled using setItemEnabled(). To work, a key must be an enabled item in an enabled QAccel..PPSee also isEnabled() and setItemEnabled()..SH "void QAccel::setItemEnabled ( int id, bool enable )"Enables the accelerator item with the identifier \fIid\fR if \fIenable\fR is TRUE, and disables \fIid\fR if \fIenable\fR is FALSE..PPTo work, an item must be enabled and be in an enabled QAccel..PPSee also isItemEnabled() and isEnabled()..SH "void QAccel::setWhatsThis ( int id, const QString & text )"Sets a What's This help for the accelerator item \fIid\fR to \fItext\fR..PPThe text will be shown when the application is in What's This mode and the user hits the accelerator key..PPTo set What's This help on a menu item (with or without an accelerator key), use QMenuData::setWhatsThis()..PPSee also whatsThis(), QWhatsThis::inWhatsThisMode(), QMenuData::setWhatsThis() and QAction::whatsThis..SH "QKeySequence QAccel::shortcutKey ( const QString & str )\fC [static]\fR"Returns the shortcut key for \fIstr\fR, or 0 if \fIstr\fR has no shortcut sequence..PPFor example, shortcutKey("E&xit") returns ALT+Key_X, shortcutKey("&Exit") returns ALT+Key_E and shortcutKey("Exit") returns 0. (In code that does not inherit the Qt namespace class, you need to write e.g. Qt::ALT+Qt::Key_X.).PPWe provide a list of common accelerators in English. At the time of this writing, Microsoft and The Open Group do not appear to have issued equivalent recommendations for other languages..SH "QKeySequence QAccel::stringToKey ( const QString & s )\fC [static]\fR"\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code..PPReturns an accelerator code for the string \fIs\fR. For example" Ctrl+O" gives CTRL+UNICODE_ACCEL+'O'. The strings "Ctrl"," Shift", "Alt" are recognized, as well as their translated equivalents in the "QAccel" scope (using QObject::tr()). Returns 0 if \fIs\fR is not recognized..PPThis function is typically used with tr(), so that accelerator keys can be replaced in translations:.PP.nf.br QPopupMenu *file = new QPopupMenu( this );.br file->insertItem( p1, tr("&Open..."), this, SLOT(open()),.br QAccel::stringToKey(tr("Ctrl+O", "File|Open")) );.br.fi.PPNotice the \fC"File|Open"\fR translator comment. It is by no means necessary, but it provides some context for the human translator..PPThe function is superfluous. Construct a QKeySequence from the string \fIs\fR for the same effect..PPSee also QObject::tr() and Internationalization with Qt..PPExample: i18n/mywidget.cpp..SH "QString QAccel::whatsThis ( int id ) const"Returns the What's This help text for the specified item \fIid\fR or QString::null if no text has been defined yet..PPSee also setWhatsThis()..SH "SEE ALSO".BR http://doc.trolltech.com/qaccel.html.BR http://www.trolltech.com/faq/tech.html.SH COPYRIGHTCopyright 1992-2001 Trolltech AS, http://www.trolltech.com. See thelicense file included in the distribution for a complete licensestatement..SH AUTHORGenerated automatically from the source code..SH BUGSIf you find a bug in Qt, please report it as described in.BR http://doc.trolltech.com/bughowto.html .Good bug reports help us to help you. Thank you..PThe definitive Qt documentation is provided in HTML format; it islocated at $QTDIR/doc/html and can be read using Qt Assistant or witha web browser. This man page is provided as a convenience for thoseusers who prefer man pages, although this format is not officiallysupported by Trolltech. .PIf you find errors in this manual page, please report them to.BR qt-bugs@trolltech.com .Please include the name of the manual page (qaccel.3qt) and the Qtversion (3.0.0).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -