QKeySequence Class

QKeySequence 类封装了快捷方式使用的按键序列。更多

头文件: #include <QKeySequence>
CMake.QKeySequence 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
QVariant 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 部分。

最好尽可能使用标准快捷键。在为非标准快捷方式创建按键序列时,应优先使用人类可读字符串,而不是硬编码的整数值。

可以使用toString() 函数将 QKeySequence 对象序列化为人类可读字符串。

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

注: 在 Apple 平台上,"Ctrl"、Qt::CTRLQt::Key_ControlQt::ControlModifier 与 Macintosh 键盘上的Command 键相对应,而 "Meta"、Qt::METAQt::Key_MetaQt::MetaModifierControl 键相对应。实际上,开发人员可以在所有平台上使用相同的快捷方式描述,他们的应用程序将自动按照预期在苹果平台上运行。

标准快捷键

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

StandardKey视窗苹果平台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
删除删除向前删除,Meta+D删除,Ctrl+D删除,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+Inns
首选项Ctrl+V,F18,Shift+InsCtrl+Shift+、
撤销Ctrl+Z,Alt+退格Ctrl+ZCtrl+Z,F14Ctrl+Z,F14
重做Ctrl+Y,Shift+Ctrl+Z,Alt+Shift+回车键Ctrl+Shift+ZCtrl+Shift+ZCtrl+Shift+Z
后退Alt+向左,退格Ctrl+[Alt+LeftAlt+Left
向前Alt+右,Shift+退格Ctrl+]Alt+ 右右键
刷新F5F5F5Ctrl+R, F5
ZoomInCtrl+PlusCtrl+PlusCtrl+PlusCtrl+Plus
ZoomOutCtrl+MinusCtrl+MinusCtrl+MinusCtrl+Minus
FullScreenF11,Alt+回车Ctrl+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+HCtrl+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左,元+B
MoveToNextWordCtrl+RightAlt+ 右Ctrl+ 右Ctrl+ 右
MoveToPreviousWordCtrl+ 左Alt+ 左Ctrl+LeftCtrl+Left
MoveToNextLine向下向下,Meta+N向下向下
MoveToPreviousLine向上向上,元+P向上向上
MoveToNextPage向下PgDown, Alt+PgDown, Meta+Down, Meta+PgDown, Meta+VPgDownPgDown
MoveToPreviousPage向上翻页PgUp、Alt+PgUp、Meta+Up、Meta+PgUpPgUp向上翻页
MoveToStartOfLine主页Ctrl+Left, Meta+Left首页首页
MoveToEndOfLine结束Ctrl+ 右,Meta+ 右结束,Ctrl+E结束,Ctrl+E
MoveToStartOfBlockAlt+向上,Meta+A
MoveToEndOfBlockAlt+向下,Meta+E
MoveToStartOfDocumentCtrl+ 主页Ctrl+向上,主页Ctrl+ 主页Ctrl+ 主页
MoveToEndOfDocumentCtrl+ 结束Ctrl+Down, 结束Ctrl+EndCtrl+End
SelectNextCharShift+ 右Shift+ 右键向右移Shift+ 右
SelectPreviousCharShift+ 左移位+左移位+左Shift+ 左
SelectNextWordCtrl+Shift+RightAlt+Shift+RightCtrl+Shift+RightCtrl+Shift+Right
SelectPreviousWordCtrl+Shift+LeftAlt+Shift+LeftCtrl+Shift+LeftCtrl+Shift+Left
SelectNextLineShift+DownShift+DownShift+DownShift+Down
SelectPreviousLineShift+上移位+上移位+上移位+向上
SelectNextPageShift+PgDownShift+PgDown移位+向下翻页移位+PgDown
SelectPreviousPage移位+Pg向上移位+Pg向上移位+Pg向上移位+Pg向上
SelectStartOfLineShift+ 主页Ctrl+Shift+LeftShift+ 主页Shift+ 主页
SelectEndOfLineShift+EndCtrl+Shift+RightShift+ 末端Shift+ 结束
SelectStartOfBlockAlt+Shift+上,Meta+Shift+A
SelectEndOfBlockAlt+Shift+Down,Meta+Shift+E
SelectStartOfDocumentCtrl+Shift+HomeCtrl+Shift+ 上,Shift+ 主页Ctrl+Shift+HomeCtrl+Shift+Home
SelectEndOfDocumentCtrl+Shift+EndCtrl+Shift+Down, Shift+EndCtrl+Shift+EndCtrl+Shift+End
DeleteStartOfWordCtrl+BackspaceAlt+BackspaceCtrl+BackspaceCtrl+Backspace
DeleteEndOfWordCtrl+DelCtrl+DelCtrl+Del
DeleteEndOfLineCtrl+KCtrl+K
DeleteCompleteLine(无)Ctrl+UCtrl+U
InsertParagraphSeparator回车回车回车回车
InsertLineSeparatorShift+EnterMeta+Enter, Meta+OShift+EnterShift+Enter
退格删除,Meta+H
取消EscapeEscape, Ctrl+.EscapeEscape

请注意,由于不同平台的标准快捷键使用的键序不同,因此仍需在每个平台上测试快捷键,以确保不会无意中为多个操作指定相同的键序。

键盘布局问题

许多键序规范是开发人员根据某些类型键盘的布局选择的,而不是选择代表操作名称首字母的按键,如Ctrl S ("Ctrl+S")或Ctrl C ("Ctrl+C")。此外,由于某些符号只能在特定键盘布局上借助修改键输入,因此用于一种键盘布局的按键序列可能映射到不同的按键,或根本没有映射到任何按键,或需要额外的修改键才能用于不同的键盘布局。

例如,快捷键Ctrl plusCtrl 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作为特定平台字符串的按键序列。这意味着它将被翻译显示,在苹果平台上,它将类似于菜单栏中的按键序列。该枚举最适合在需要向用户显示字符串时使用。
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将光标移至块末此快捷键仅在苹果平台上使用。
QKeySequence::MoveToEndOfDocument43将光标移至文档末尾
QKeySequence::MoveToEndOfLine39将光标移至行尾
QKeySequence::MoveToNextChar30将光标移至下一个字符
QKeySequence::MoveToNextLine34将光标移至下一行
QKeySequence::MoveToNextPage36将光标移至下一页
QKeySequence::MoveToNextWord32光标移至下一字。
QKeySequence::MoveToPreviousChar31将光标移至上一个字符。
QKeySequence::MoveToPreviousLine35光标移至上一行
QKeySequence::MoveToPreviousPage37光标移至前一页。
QKeySequence::MoveToPreviousWord33将光标移至前一个字。
QKeySequence::MoveToStartOfBlock40将光标移至块的起始位置。此快捷键仅用于苹果平台。
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将选择范围扩展到文本块的末尾。此快捷键仅在苹果平台上使用。
QKeySequence::SelectEndOfDocument57将选区扩展至文档末尾。
QKeySequence::SelectEndOfLine53将选区扩展到行尾。
QKeySequence::SelectNextChar44扩展选区至下一个字符。
QKeySequence::SelectNextLine48将选区扩展到下一行。
QKeySequence::SelectNextPage50将选区扩展到下一页。
QKeySequence::SelectNextWord46扩展选择至下一个单词。
QKeySequence::SelectPreviousChar45将选择扩展到上一个字符。
QKeySequence::SelectPreviousLine49扩展选择至上行。
QKeySequence::SelectPreviousPage51将选择扩展到上一页。
QKeySequence::SelectPreviousWord47扩展选择到上一个字。
QKeySequence::SelectStartOfBlock54将选区扩展到文本块的开头。此快捷键仅用于苹果平台。
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,k3k4

另请参见 QKeyCombination

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

构建一个最多包含 4 个按键的按键序列k1,k2,k3k4

按键代码列于Qt::Key ,可与修饰符(见Qt::KeyboardModifier )组合,如Qt::ShiftModifier,Qt::ControlModifier,Qt::AltModifierQt::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 "等字符串在 "QShortcut"上下文中使用QObject::tr() 进行翻译。

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

在 Apple 平台上,如果formatQKeySequence::NativeText ,返回的字符串与菜单栏中显示的序列相似;否则,字符串将使用 "可移植 "格式,适合写入文件。

另请参阅 fromString() 。

QVariant 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)。

该函数在某些情况下非常有用,例如,如果要在QMap 中使用QKeySequence 对象作为键。

另请参阅 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)

Move-assignsother 到此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 操作符的格式

© 2025 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.