Home · All Classes · Modules

QKeySequence Class Reference
[QtGui module]

The QKeySequence class encapsulates a key sequence as used by shortcuts. More...

Types

Methods

Static Methods

Special Methods


Detailed Description

A Python int object or a QString may be used whenever a QKeySequence is expected.

The QKeySequence class encapsulates a key sequence as used by shortcuts.

A key sequence consists of up to four keyboard codes, each optionally combined with modifiers, such as Qt.SHIFT, Qt.CTRL, Qt.ALT or Qt.META. For example, Qt.CTRL + Qt.Key_P might be a sequence used as a shortcut for printing a document. Valid codes for keys and modifiers are listed in Qt.Key and Qt.Modifier. As an alternative, use the unicode code point of the character; for example, 'A' gives the same key sequence as Qt.Key_A.

Key sequences can be constructed either from an integer key code, or from a human readable translatable string such as "Ctrl+X,Alt+Space". A key sequence can be cast to a QString to obtain a human readable translated version of the sequence. Translations are done in the "QShortcut" context.

Note: On Mac OS X, references to "Ctrl", Qt.CTRL, Qt.Control and Qt.ControlModifier correspond to the Command keys on the Macintosh keyboard, and references to "Meta", Qt.META, Qt.Meta and Qt.MetaModifier correspond to the Control keys. Developers on Mac OS X can use the same shortcut descriptions across all platforms, and their applications will automatically work as expected on Mac OS X.

The toString() function produces human-readable strings for use in menus. On Mac OS X, the appropriate symbols are used to describe keyboard shortcuts using special keys on the Macintosh keyboard.

See also QShortcut.


Type Documentation

QKeySequence.SequenceFormat

Constant Value Description
QKeySequence.NativeText 0 The key sequence as a platform specific string. This means that it will be shown translated and on the Mac it will resemble a keysequence from the menu bar. This enum is best used when you want to display the string to the user.
QKeySequence.PortableText 1 The key sequence is given in a "portable" format, suitable for reading and writing to a file. In many cases, it will look similar to the native text on Windows and X11.


QKeySequence.SequenceMatch

Constant Value Description
QKeySequence.NoMatch 0 The key sequences are different; not even partially matching.
QKeySequence.PartialMatch 1 The key sequences match partially, but are not the same.
QKeySequence.ExactMatch 2 The key sequences are the same.



Method Documentation

QKeySequence.__init__ (self)

Constructs an empty key sequence.

QKeySequence.__init__ (self, QString key)

Creates a key sequence from the key string. For example "Ctrl+O" gives CTRL+'O'. The strings "Ctrl", "Shift", "Alt" and "Meta" are recognized, as well as their translated equivalents in the "QShortcut" context (using QObject.tr()).

Up to four key codes may be entered by separating them with commas, e.g. "Alt+X,Ctrl+S,Q".

This contructor is typically used with tr(), so that shortcut keys can be replaced in translations:

    QMenu *file = new QMenu(this);
    file->addAction(tr("&Open..."), this, SLOT(open()),
                      QKeySequence(tr("Ctrl+O", "File|Open")));

Note the "File|Open" translator comment. It is by no means necessary, but it provides some context for the human translator.

QKeySequence.__init__ (self, int k1, int k2 = 0, int k3 = 0, int k4 = 0)

Constructs a key sequence with up to 4 keys k1, k2, k3 and k4.

The key codes are listed in Qt.Key and can be combined with modifiers (see Qt.Modifier) such as Qt.SHIFT, Qt.CTRL, Qt.ALT, or Qt.META.

QKeySequence.__init__ (self, QVariant)

Copy constructor. Makes a copy of keysequence.

QKeySequence.__init__ (self, QKeySequence ks)

unsigned long QKeySequence.count (self)

Returns the number of keys in the key sequence. The maximum is 4.

QKeySequence QKeySequence.fromString (QString str, SequenceFormat format = QKeySequence.PortableText)

Return a QKeySequence from the string str based on format.

This function was introduced in Qt 4.1.

See also toString().

bool QKeySequence.isDetached (self)

bool QKeySequence.isEmpty (self)

Returns true if the key sequence is empty; otherwise returns false.

SequenceMatch QKeySequence.matches (self, QKeySequence seq)

Matches the sequence with seq. Returns ExactMatch if successful, PartialMatch if seq matches incompletely, and NoMatch if the sequences have nothing in common. Returns NoMatch if seq is shorter.

QKeySequence QKeySequence.mnemonic (QString text)

Returns the shortcut key sequence for the mnemonic in text, or an empty key sequence if no mnemonics are found.

For example, mnemonic("E&xit") returns Qt.ALT+Qt.Key_X, mnemonic("&Quit") returns ALT+Key_Q, and mnemonic("Quit") returns an empty QKeySequence.

We provide a list of common mnemonics in English. At the time of writing, Microsoft and Open Group do not appear to have issued equivalent recommendations for other languages.

QString QKeySequence.toString (self, SequenceFormat format = QKeySequence.PortableText)

Return a string representation of the key sequence based on format.

This function was introduced in Qt 4.1.

See also fromString().

bool QKeySequence.__eq__ (self, QKeySequence other)

bool QKeySequence.__ge__ (self, QKeySequence other)

int QKeySequence.__getitem__ (self, unsigned long i)

bool QKeySequence.__gt__ (self, QKeySequence other)

int QKeySequence.__int__ (self)

bool QKeySequence.__le__ (self, QKeySequence other)

bool QKeySequence.__lt__ (self, QKeySequence ks)

bool QKeySequence.__ne__ (self, QKeySequence other)


PyQt 4.0.1 for X11Copyright © Riverbank Computing Ltd and Trolltech AS 2006Qt 4.1.4