本页内容

QKeySequence Class

QKeySequence 类封装了快捷键中使用的键序列。更多内容...

头文件: #include <QKeySequence>
CMake: find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: QT += gui

公共类型

enum SequenceFormat { NativeText, PortableText }
enum SequenceMatch { NoMatch, PartialMatch, ExactMatch }
enum StandardKey { AddTab, Back, Backspace, Bold, Close, …, Cancel }

公共函数

QKeySequence()
QKeySequence(QKeySequence::StandardKey key)
QKeySequence(const QString &key, QKeySequence::SequenceFormat format = NativeText)
QKeySequence(QKeyCombination k1, QKeyCombination k2 = QKeyCombination::fromCombined(0), QKeyCombination k3 = QKeyCombination::fromCombined(0), QKeyCombination k4 = QKeyCombination::fromCombined(0))
QKeySequence(int k1, int k2 = 0, int k3 = 0, int k4 = 0)
QKeySequence(const QKeySequence &keysequence)
~QKeySequence()
int count() const
bool isEmpty() const
QKeySequence::SequenceMatch matches(const QKeySequence &seq) const
void swap(QKeySequence &other)
QString toString(QKeySequence::SequenceFormat format = PortableText) const
operator QVariant() const
bool operator!=(const QKeySequence &other) const
bool operator<(const QKeySequence &other) const
bool operator<=(const QKeySequence &other) const
QKeySequence &operator=(QKeySequence &&other)
QKeySequence &operator=(const QKeySequence &other)
bool operator==(const QKeySequence &other) const
bool operator>(const QKeySequence &other) const
bool operator>=(const QKeySequence &other) const
QKeyCombination operator[](uint index) const

静态公共成员

QKeySequence fromString(const QString &str, QKeySequence::SequenceFormat format = PortableText)
QList<QKeySequence> keyBindings(QKeySequence::StandardKey key)
QList<QKeySequence> listFromString(const QString &str, QKeySequence::SequenceFormat format = PortableText)
QString listToString(const QList<QKeySequence> &list, QKeySequence::SequenceFormat format = PortableText)
QKeySequence mnemonic(const QString &text)
size_t qHash(const QKeySequence &key, size_t seed = 0)
void qt_set_sequence_auto_mnemonic(bool b)
QDataStream &operator<<(QDataStream &stream, const QKeySequence &sequence)
QDataStream &operator>>(QDataStream &stream, QKeySequence &sequence)

详细说明

在最常见的形式中,键序列描述了一组必须同时按下才能执行某项操作的键。键序列与QAction 对象配合使用,用于指定可用于触发操作的键盘快捷键。

可以通过以下三种不同方式构建键序列以用作键盘快捷键:

例如,Ctrl P 可能是一组用于打印文档的快捷键序列,可以通过以下任何一种方式指定:

QKeySequence(QKeySequence::Print);
QKeySequence(tr("Ctrl+P"));
QKeySequence(tr("Ctrl+p"));
QKeySequence(Qt::CTRL | Qt::Key_P);
QKeySequence(Qt::CTRL + Qt::Key_P); // deprecated

请注意,对于字母,指定字符串中使用的大小写不影响结果。 在上述示例中,用户无需按住Shift 键来激活指定为“Ctrl+P”的快捷键。然而,对于其他键而言,将Shift 作为未指定的额外修饰键可能会导致那些键盘布局与开发者所用布局不同的应用程序用户产生混淆。更多详细信息请参阅下文的“Keyboard Layout Issues ”部分。

建议尽可能使用标准快捷键。在为非标准快捷键创建键序列时,应优先使用易于理解的字符串,而非硬编码的整数值。

QKeySequence 对象可通过toString() 函数序列化为易于理解的字符串。

指定硬编码键码的另一种方法是使用字符的 Unicode 码点;例如,'A' 产生的键序列与Qt::Key_A 相同。

注意:在 Apple 平台上,“Ctrl”、Qt::CTRL 、Qt::Key_Control 和Qt::ControlModifier 分别对应 Macintosh 键盘上的Command 键,而“Meta”、Qt::META 、Qt::Key_Meta 和Qt::MetaModifier 则分别对应Control 键。实际上,开发人员可以在所有平台上使用相同的快捷键描述,他们的应用程序将在 Apple 平台上自动按预期运行。

标准快捷键

QKeySequence 定义了许多standard keyboard shortcuts ,以减少在典型应用程序中设置操作所需的 effort。下表列出了四个广泛使用的平台上应用程序常用于这些标准快捷键的一些常见键序列。 请注意,在 Apple 平台上,Ctrl 值对应于 Macintosh 键盘上的Command 键,而Meta 值则对应于Control 键。

StandardKeyWindowsApple 平台KDE PlasmaGNOME
HelpContentsF1Ctrl+?F1F1
WhatsThisShift+F1Shift+F1Shift+F1Shift+F1
打开Ctrl+OCtrl+OCtrl+OCtrl+O
关闭Ctrl+F4、Ctrl+WCtrl+W、Ctrl+F4Ctrl+WCtrl+W
保存Ctrl+SCtrl+SCtrl+SCtrl+S
退出Ctrl+QCtrl+QCtrl+Q
SaveAsCtrl+Shift+SCtrl+Shift+SCtrl+Shift+SCtrl+Shift+S
新建Ctrl+NCtrl+NCtrl+NCtrl+N
删除Del向前删除,Meta+DDel,Ctrl+DDel,Ctrl+D
剪切Ctrl+X,Shift+DelCtrl+X、Meta+KCtrl+X、F20、Shift+DelCtrl+X、F20、Shift+Del
复制Ctrl+C、Ctrl+InsCtrl+CCtrl+C、F16、Ctrl+InsCtrl+C、F16、Ctrl+Ins
粘贴Ctrl+V,Shift+InsCtrl+V, Meta+YCtrl+V、F18、Shift+InsCtrl+V、F18、Shift+Ins
首选项Ctrl+,Ctrl+Shift+,
撤销Ctrl+Z,Alt+BackspaceCtrl+ZCtrl+Z, F14Ctrl+Z, F14
重做Ctrl+Y、Shift+Ctrl+Z、Alt+Shift+BackspaceCtrl+Shift+ZCtrl+Shift+ZCtrl+Shift+Z
返回Alt+向左,退格键Ctrl+[Alt+向左Alt+左键
前进Alt+右键,Shift+退格键Ctrl+]Alt+右Alt+右
刷新F5F5F5Ctrl+R,F5
ZoomInCtrl+加号Ctrl+加号Ctrl+加号Ctrl+加号
ZoomOutCtrl+减号Ctrl+减号Ctrl+减号Ctrl+减号
FullScreenF11、Alt+EnterCtrl+Meta+FF11,Ctrl+Shift+FCtrl+F11
打印Ctrl+PCtrl+PCtrl+PCtrl+P
AddTabCtrl+TCtrl+TCtrl+Shift+N,Ctrl+TCtrl+T
NextChildCtrl+Tab、向前、Ctrl+F6Ctrl+},向右,Ctrl+TabCtrl+Tab、向前、Ctrl+逗号Ctrl+Tab,向前
PreviousChildCtrl+Shift+Tab、向后、Ctrl+Shift+F6Ctrl+{,向后,Ctrl+Shift+TabCtrl+Shift+Tab,向后,Ctrl+句号Ctrl+Shift+Tab,向后
查找Ctrl+FCtrl+FCtrl+FCtrl+F
FindNextF3、Ctrl+GCtrl+GF3Ctrl+G, F3
FindPreviousShift+F3, Ctrl+Shift+GCtrl+Shift+GShift+F3Ctrl+Shift+G、Shift+F3
替换Ctrl+H(无)Ctrl+RCtrl+H
SelectAllCtrl+ACtrl+ACtrl+ACtrl+A
取消选择Ctrl+Shift+ACtrl+Shift+A
加粗Ctrl+BCtrl+BCtrl+BCtrl+B
斜体Ctrl+ICtrl+ICtrl+ICtrl+I
下划线Ctrl+UCtrl+UCtrl+UCtrl+U
MoveToNextChar右右Meta+F向右向右向右向右
MoveToPreviousChar左左,Meta+B左左
MoveToNextWordCtrl+右Alt+右Ctrl+右Ctrl+向右
MoveToPreviousWordCtrl+左Alt+左Ctrl+左Ctrl+左
MoveToNextLine向下向下,Meta+N向下向下
MoveToPreviousLine向上上,Meta+P上上
MoveToNextPagePgDownPgDown、Alt+PgDown、Meta+Down、Meta+PgDown、Meta+VPgDownPgDown
MoveToPreviousPagePgUpPgUp、Alt+PgUp、Meta+Up、Meta+PgUpPgUpPgUp
MoveToStartOfLineHomeCtrl+左键、Meta+左键首页首页
MoveToEndOfLineEndCtrl+右,Meta+右End,Ctrl+EEnd,Ctrl+E
MoveToStartOfBlock(无)Alt+上箭头,Meta+A(无)(无)
MoveToEndOfBlock(无)Alt+下箭头,Meta+E(无)(无)
MoveToStartOfDocumentCtrl+HomeCtrl+上箭头,HomeCtrl+HomeCtrl+Home
MoveToEndOfDocumentCtrl+EndCtrl+向下,EndCtrl+EndCtrl+End
SelectNextCharShift+右箭头Shift+右箭头Shift+右箭头Shift+右箭头
SelectPreviousCharShift+左Shift+向左Shift+左Shift+左
SelectNextWordCtrl+Shift+右Alt+Shift+右Ctrl+Shift+右Ctrl+Shift+右
SelectPreviousWordCtrl+Shift+左Alt+Shift+左Ctrl+Shift+左Ctrl+Shift+左
SelectNextLineShift+向下Shift+向下Shift+向下Shift+向下
SelectPreviousLineShift+上Shift+上Shift+上Shift+上
SelectNextPageShift+PgDownShift+PgDownShift+向下翻页Shift+PgDown
SelectPreviousPageShift+PgUpShift+PgUpShift+PgUpShift+PgUp
SelectStartOfLineShift+HomeCtrl+Shift+向左Shift+HomeShift+Home
SelectEndOfLineShift+EndCtrl+Shift+右Shift+EndShift+End
SelectStartOfBlock(无)Alt+Shift+上箭头,Meta+Shift+A(无)(无)
SelectEndOfBlock(无)Alt+Shift+向下键,Meta+Shift+E(无)(无)
SelectStartOfDocumentCtrl+Shift+HomeCtrl+Shift+上箭头,Shift+HomeCtrl+Shift+HomeCtrl+Shift+Home
SelectEndOfDocumentCtrl+Shift+EndCtrl+Shift+向下,Shift+EndCtrl+Shift+EndCtrl+Shift+End
DeleteStartOfWordCtrl+BackspaceAlt+BackspaceCtrl+退格键Ctrl+退格键
DeleteEndOfWordCtrl+Del(无)Ctrl+DelCtrl+Del
DeleteEndOfLine(无)(无)Ctrl+KCtrl+K
DeleteCompleteLine(无)(无)Ctrl+UCtrl+U
InsertParagraphSeparator回车回车回车回车
InsertLineSeparatorShift+EnterMeta+Enter、Meta+OShift+EnterShift+Enter
退格键(无)Delete,Meta+H(无)(无)
取消EscEsc,Ctrl+.EscEscape

请注意,由于不同平台使用的标准快捷键序列各不相同,您仍需在每个平台上测试您的快捷键,以确保不会无意中将相同的键序列分配给多个操作。

键盘布局问题

许多键序列规范是由开发人员根据特定类型的键盘布局选择的,而不是选择代表操作名称首字母的键,例如Ctrl S (“Ctrl+S”)或Ctrl C (“Ctrl+C”)。 此外,由于在某些键盘布局中,某些符号只能借助修饰键输入,因此 intended for use with one keyboard layout 的键序列在其他键盘布局上可能会映射到不同的键、完全不映射到任何键,或者需要使用额外的修饰键。

例如,快捷键Ctrl plus 和Ctrl minus 常被用作图形应用程序中缩放操作的快捷键,它们通常分别指定为“Ctrl++”和“Ctrl+-”。然而,这些快捷键的指定和解释方式取决于键盘布局。 使用挪威语键盘的用户会注意到,+ 和- 键在键盘上并不相邻,但仍能激活这两个快捷键,而无需按下Shift 键。然而,使用英国键盘的用户则需要按住Shift 键才能输入+ 符号,这使得该快捷键实际上等同于“Ctrl+Shift+=”。

虽然有些开发者可能会选择明确指定键盘上所有用于触发快捷键的修饰键,但这也会导致使用不同键盘布局的用户遇到意料之外的行为。

例如,一位使用英国键盘的开发者可能决定将“Ctrl+Shift+=”指定为键序列,以便创建一个恰好与Ctrl plus 行为相同的快捷键。然而,在挪威键盘上,= 键需要通过Shift 键来访问,这使得所需的快捷键实际上变成了Ctrl Shift Shift = (一种无法实现的键组合)。

因此,在指定适用于多种不同键盘布局的键序列时,无论是易于理解的字符串还是硬编码的键码,都可能带来问题。只有使用standard shortcuts 才能保证用户能够使用开发者预期的快捷键。

尽管如此,我们仍可通过确保使用易于理解的字符串来解决这一问题,从而为不同语言的用户提供键序列的翻译。对于键盘布局符合其所用语言典型格式的用户而言,这种方法是有效的。

GNU Emacs 风格的键序列

类似于GNU Emacs 中使用的键序列(最多支持四个键码),可以通过多参数构造器创建,或者通过传递一个由逗号分隔的、易于人类阅读的键序列字符串来实现。

例如,键序列Ctrl X 紧跟Ctrl C ,可以通过以下任一方式指定:

QKeySequence(tr("Ctrl+X, Ctrl+C"));
QKeySequence(Qt::CTRL | Qt::Key_X, Qt::CTRL | Qt::Key_C);
QKeySequence(Qt::CTRL + Qt::Key_X, Qt::CTRL + Qt::Key_C); // deprecated

警告: 在创建 QKeySequence 之前,必须先构建一个 QApplication 实例;否则,您的应用程序可能会崩溃。

另请参阅 QShortcut 。

成员类型文档

enum QKeySequence::SequenceFormat

常数值描述
QKeySequence::NativeText0作为平台特定字符串的键序列。这意味着它将以翻译后的形式显示,在 Apple 平台上其外观将类似于菜单栏中的键序列。当您需要向用户显示该字符串时,最好使用此枚举。
QKeySequence::PortableText1键序列采用“可移植”格式给出,适合读写到文件中。在许多情况下,它在 Windows 和 X11 上的显示效果将与原生文本相似。

enum QKeySequence::SequenceMatch

常数值描述
QKeySequence::NoMatch0密钥序列不同;甚至没有部分匹配。
QKeySequence::PartialMatch1密钥序列部分匹配,但并不完全相同。
QKeySequence::ExactMatch2密钥序列相同。

enum QKeySequence::StandardKey

该枚举表示标准键位绑定。可用于为QAction 分配与平台相关的键盘快捷键。

请注意,这些键位绑定与平台相关。可通过调用 `keyBindings()` 方法查询当前已绑定的快捷键。

常量值描述
QKeySequence::AddTab19添加新标签页。
QKeySequence::Back13向后导航。
QKeySequence::Backspace69删除前一个字符。
QKeySequence::Bold27加粗文本。
QKeySequence::Close4关闭文档/标签页。
QKeySequence::Copy9复制。
QKeySequence::Cut8剪切。
QKeySequence::Delete7删除。
QKeySequence::DeleteEndOfLine60删除行尾。
QKeySequence::DeleteEndOfWord59从光标末尾删除单词。
QKeySequence::DeleteStartOfWord58删除单词开头至光标处的内容。
QKeySequence::DeleteCompleteLine68删除整行。
QKeySequence::Find22在文档中查找。
QKeySequence::FindNext23查找下一个结果。
QKeySequence::FindPrevious24查找上一个结果。
QKeySequence::Forward14向前导航。
QKeySequence::HelpContents1打开帮助内容。
QKeySequence::InsertLineSeparator62插入新行。
QKeySequence::InsertParagraphSeparator61插入新段落。
QKeySequence::Italic28斜体文本。
QKeySequence::MoveToEndOfBlock41将光标移至块末尾。此快捷键仅在 Apple 平台上使用。
QKeySequence::MoveToEndOfDocument43将光标移至文档末尾。
QKeySequence::MoveToEndOfLine39将光标移至行尾。
QKeySequence::MoveToNextChar30将光标移至下一个字符。
QKeySequence::MoveToNextLine34将光标移至下一行。
QKeySequence::MoveToNextPage36将光标移至下一页。
QKeySequence::MoveToNextWord32将光标移至下一个单词。
QKeySequence::MoveToPreviousChar31将光标移至上一个字符处。
QKeySequence::MoveToPreviousLine35将光标移至上一行。
QKeySequence::MoveToPreviousPage37将光标移至上一页。
QKeySequence::MoveToPreviousWord33将光标移至上一个单词。
QKeySequence::MoveToStartOfBlock40将光标移至块的开头。此快捷键仅在 Apple 平台上使用。
QKeySequence::MoveToStartOfDocument42将光标移至文档开头。
QKeySequence::MoveToStartOfLine38将光标移至行首。
QKeySequence::New6创建新文档。
QKeySequence::NextChild20导航到下一个选项卡或子窗口。
QKeySequence::Open3打开文档。
QKeySequence::Paste10粘贴。
QKeySequence::Preferences64打开“首选项”对话框。
QKeySequence::PreviousChild21导航到上一个选项卡或子窗口。
QKeySequence::Print18打印文档。
QKeySequence::Quit65退出应用程序。
QKeySequence::Redo12重做。
QKeySequence::Refresh15刷新或重新加载当前文档。
QKeySequence::Replace25查找和替换。
QKeySequence::SaveAs63在提示用户输入文件名后保存文档。
QKeySequence::Save5保存文档。
QKeySequence::SelectAll26全选文本。
QKeySequence::Deselect67取消选中文本。自 5.1 起
QKeySequence::SelectEndOfBlock55将选区扩展到文本块的末尾。此快捷键仅在 Apple 平台上使用。
QKeySequence::SelectEndOfDocument57将选区扩展到文档末尾。
QKeySequence::SelectEndOfLine53将选区扩展到行尾。
QKeySequence::SelectNextChar44将选区扩展到下一个字符。
QKeySequence::SelectNextLine48将选区扩展到下一行。
QKeySequence::SelectNextPage50将选区扩展到下一页。
QKeySequence::SelectNextWord46将选区扩展到下一个单词。
QKeySequence::SelectPreviousChar45将选区扩展到上一个字符。
QKeySequence::SelectPreviousLine49将选区扩展到上一行。
QKeySequence::SelectPreviousPage51将选定范围扩展到上一页。
QKeySequence::SelectPreviousWord47将选区扩展到前一个单词。
QKeySequence::SelectStartOfBlock54将选区扩展到文本块的开头。此快捷键仅在 Apple 平台上使用。
QKeySequence::SelectStartOfDocument56将选区扩展到文档开头。
QKeySequence::SelectStartOfLine52将选区扩展到行首。
QKeySequence::Underline29给文本加下划线。
QKeySequence::Undo11撤销。
QKeySequence::UnknownKey0未绑定键。
QKeySequence::WhatsThis2激活“这是什么”。
QKeySequence::ZoomIn16放大。
QKeySequence::ZoomOut17缩小。
QKeySequence::FullScreen66在全屏和非全屏模式之间切换。
QKeySequence::Cancel70取消当前操作。

成员函数文档

QKeySequence::QKeySequence()

构建一个空的键序列。

QKeySequence::QKeySequence(QKeySequence::StandardKey key)

根据给定的key 构建一个QKeySequence对象。结果将取决于当前运行的平台。

生成的对象将基于key 的键绑定列表中的第一个元素。

QKeySequence::QKeySequence(const QString &key, QKeySequence::SequenceFormat format = NativeText)

根据format ,从字符串key 生成键序列。

例如,“Ctrl+O”将生成 CTRL+'O'。系统会识别“Ctrl”、“Shift”、“Alt”和“Meta”这些字符串,以及它们在“QShortcut ”上下文中通过QObject::tr() 转换后的等效形式。

最多可输入四个键码,用逗号分隔,例如“Alt+X,Ctrl+S,Q”。

该构造函数通常与tr() 配合使用,以便在翻译中替换快捷键:

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

请注意“File|Open”这一翻译注释。虽然它绝非必需,但能为人译者提供一些上下文信息。

QKeySequence::QKeySequence(QKeyCombination k1, QKeyCombination k2 = QKeyCombination::fromCombined(0), QKeyCombination k3 = QKeyCombination::fromCombined(0), QKeyCombination k4 = QKeyCombination::fromCombined(0))

构建一个最多包含 4 个键的键序列:k1 、k2 、k3 和k4 。

另请参阅 QKeyCombination 。

QKeySequence::QKeySequence(int k1, int k2 = 0, int k3 = 0, int k4 = 0)

构建一个包含最多 4 个键的键序列:k1 、k2 、k3 和k4 。

键码列于Qt::Key 中,可与修饰符(参见Qt::KeyboardModifier )组合使用,例如Qt::ShiftModifier 、Qt::ControlModifier 、Qt::AltModifier 或Qt::MetaModifier 。

QKeySequence::QKeySequence(const QKeySequence &keysequence)

复制构造函数。创建keysequence 的副本。

[noexcept] QKeySequence::~QKeySequence()

销毁密钥序列。

int QKeySequence::count() const

返回键序列中的键的个数。最大值为 4。

[static] QKeySequence QKeySequence::fromString(const QString &str, QKeySequence::SequenceFormat format = PortableText)

根据format ,从字符串str 中返回一个QKeySequence 。

另请参阅 toString()。

bool QKeySequence::isEmpty() const

如果键序列为空,则返回true ;否则返回false。

[static] QList<QKeySequence> QKeySequence::keyBindings(QKeySequence::StandardKey key)

返回给定key 的快捷键映射列表。调用此函数的结果会因目标平台而异。列表的第一个元素表示该平台的主快捷键。如果结果包含多个条目,则可将其视为同一平台上针对给定key 的替代快捷键。

[static] QList<QKeySequence> QKeySequence::listFromString(const QString &str, QKeySequence::SequenceFormat format = PortableText)

根据format ,从字符串str 中返回一个QKeySequence 列表。

另请参阅 fromString() 和listToString()。

[static] QString QKeySequence::listToString(const QList<QKeySequence> &list, QKeySequence::SequenceFormat format = PortableText)

根据format 返回list 的字符串表示形式。

另请参阅 toString() 和listFromString()。

QKeySequence::SequenceMatch QKeySequence::matches(const QKeySequence &seq) const

匹配序列与seq 。若匹配成功,返回ExactMatch ;若seq 匹配不完全,返回PartialMatch ;若两个序列没有任何共同点,返回NoMatch 。若seq 较短,返回NoMatch 。

[static] QKeySequence QKeySequence::mnemonic(const QString &text)

返回text 中该助记符对应的快捷键序列;若未找到任何助记符,则返回一个空键序列。

例如,mnemonic("E&xit") 返回Qt::ALT+Qt::Key_X ,mnemonic("&Quit") 返回ALT+Key_Q ,而 mnemonic("Quit") 返回一个空的QKeySequence 。

[noexcept] void QKeySequence::swap(QKeySequence &other)

将此键序列与other 互换。此操作速度极快,且绝不会失败。

QString QKeySequence::toString(QKeySequence::SequenceFormat format = PortableText) const

根据format 返回键序列的字符串表示形式。

例如,值Qt::CTRL+Qt::Key_O 会返回 "Ctrl+O"。如果键序列包含多个键码,则在返回的字符串中,每个键码之间用逗号分隔,例如 "Alt+X, Ctrl+Y, Z"。 字符串“Ctrl”、“Shift”等将使用QObject::tr()在“QShortcut ”上下文中进行转换。

如果键序列中没有键,则返回空字符串。

在 Apple 平台上,如果format 为QKeySequence::NativeText ,则返回的字符串与菜单栏中显示的序列相似;否则,该字符串采用“可移植”格式,适合写入文件。

另请参阅 fromString()。

QKeySequence::operator QVariant() const

将键序列作为QVariant

bool QKeySequence::operator!=(const QKeySequence &other) const

如果该键序列不等于other 中的键序列,则返回true ;否则返回false 。

bool QKeySequence::operator<(const QKeySequence &other) const

对该键序列与other 键序列进行任意比较。唯一能保证的是:若两个键序列相等,则该运算符返回false ;若两个键序列不相等,则(ks1 < ks2) == !(ks2 < ks1)。

在某些情况下,此函数非常有用,例如当您希望将QKeySequence 对象用作QMap 中的键时。

另请参阅 operator==()、operator!=()、operator>()、operator<=() 以及operator>=()。

bool QKeySequence::operator<=(const QKeySequence &other) const

如果该键序列小于或等于other 中的键序列,则返回true ;否则返回false 。

另请参阅 operator==()、operator!=()、operator<()、operator>() 以及operator>=()。

[noexcept] QKeySequence &QKeySequence::operator=(QKeySequence &&other)

将other 通过Move操作赋值给该QKeySequence 实例。

QKeySequence &QKeySequence::operator=(const QKeySequence &other)

赋值运算符。将other 键序列赋值给该对象。

bool QKeySequence::operator==(const QKeySequence &other) const

如果该键序列与other 键序列相等,则返回true ;否则返回false 。

bool QKeySequence::operator>(const QKeySequence &other) const

如果该键序列大于other 键序列,则返回true ;否则返回false 。

另请参阅 operator==()、operator!=()、operator<()、operator<=(),以及operator>=()。

bool QKeySequence::operator>=(const QKeySequence &other) const

如果该键序列大于或等于other 键序列,则返回true ;否则返回false 。

另请参阅 operator==()、operator!=()、operator<()、operator>()、以及operator<=()。

QKeyCombination QKeySequence::operator[](uint index) const

返回键序列中位置为index 的元素的引用。此方法仅可用于读取元素。

相关的非成员

[noexcept] size_t qHash(const QKeySequence &key, size_t seed = 0)

返回key 的哈希值,并使用seed 作为计算的种子。

void qt_set_sequence_auto_mnemonic(bool b)

指定是否应遵循菜单项、标签等的助记符。在 Windows 和 X11 系统上,此功能默认开启;在 macOS 系统上,默认关闭。当此功能关闭时(即当 `b ` 为 false 时),`QKeySequence::mnemonic()` 始终返回一个空字符串。

注意:此 函数未在 Qt 的任何头文件中声明。若要在应用程序中使用它,请在调用前声明该函数的原型。

另请参阅 QShortcut 。

QDataStream &operator<<(QDataStream &stream, const QKeySequence &sequence)

将键sequence 写入stream 。

另请参阅 QDataStream 运算符的格式。

QDataStream &operator>>(QDataStream &stream, QKeySequence &sequence)

从stream 中读取一组键,并将其写入键sequence 中。

另请参阅 QDataStream 运算符的格式。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.