Qt菜单栏快捷方式不起作用,选项下没有下划线 [英] Qt menubar shortcut doesn't work and no underline under option

查看:40
本文介绍了Qt菜单栏快捷方式不起作用,选项下没有下划线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有简单主窗口的实现:

#include "mainwindow.h"

#include <QtWidgets>

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
    QAction *someAction = new QAction(tr("&Action"), this);
    someAction->setShortcuts(QKeySequence::Quit);
    connect(someAction, &QAction::triggered, this, &QWidget::close);

    QMenu* someMenu = menuBar()->addMenu(tr("&SomeMenu"));
    someMenu->addAction(someAction);
}

菜单选项如下所示:

我希望在 Action 的字母 A 下会有下划线,并且快捷键 Ctrl+Q 会退出程序.但是按 Ctrl+Q 什么也不做,也没有下划线.但是,当我用鼠标单击此菜单选项时,它会按预期工作.这是在使用 Qt 5 的 Ubuntu 上测试的.如何让快捷方式和下划线正常工作?

I would expect that there would be underline under leter A of word Action and that shortcut Ctrl+Q would quit program. However pressing Ctrl+Q does nothing and there is no underline. However when I click on this menu option by mouse then it works as expected. This was tested on Ubuntu with Qt 5. How to make the shortcut and underline work properly?

推荐答案

这样问题就解决了.我之前通过 apt-get 安装了 Qt 5.2.1,这是 Ubuntu 14.04.我已经从官方网站安装了 Qt 5.4.0,将 Qt Creator 配置为使用这个并使用相同的代码一切开始工作 - 快捷方式工作和下划线在菜单选项下.

So the problem is solved. I had previously installed Qt 5.2.1 by apt-get and this is Ubuntu 14.04. I have installed Qt 5.4.0 from official website, configured Qt Creator to use this one and using the same code everything started to work - shortcuts work and underline is under menu option.

这篇关于Qt菜单栏快捷方式不起作用,选项下没有下划线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆