Qt Mac(重新)移动“特殊字符..."编辑菜单中的操作 [英] Qt Mac (Re)move "Special Characters..." action in Edit menu

查看:93
本文介绍了Qt Mac(重新)移动“特殊字符..."编辑菜单中的操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Qt中开发一个经常重建其菜单的应用程序.但是,当我们调用clear()并在菜单中重新添加所需的动作时,特殊字符..."似乎仍保留在菜单中.有什么方法可以删除此动作或将其移到QMenu的底部吗?

I am developing an application in Qt that rebuilds its menus very often. However, when we call clear(), and re-add the actions that we want in the menu, "Special Characters..." appears to remain in the menu. Is there any way to remove, or move this action to the bottom of the QMenu?

以下是重建菜单的代码:

Here is the code that rebuilds the menu:

void MainWindow::initMenus(Tab* tab)
{
menuBar()->clear();
menuFile->clear();
menuEdit->clear();
menuSettings->clear();
menuHelp->clear();
ui_toolBar->clear();

menuBar()->addMenu(menuFile);
menuBar()->addMenu(menuEdit);

menuFile->addAction(actionNew);
menuFile->addAction(actionOpen);
if(tab) tab->addActionsFile(menuFile);
menuFile->addSeparator();
menuFile->addAction(actionNext);
menuFile->addAction(actionPrevious);
menuFile->addAction(actionClose);
menuFile->addSeparator();
menuFile->addAction(actionQuit);

if(tab) {
    tab->addActionsEdit(menuEdit);
    menuEdit->addSeparator();
    tab->addActionsHelp(menuHelp);
    menuHelp->addSeparator();
}

menuEdit->addAction(actionEditor_Settings);

menuHelp->addSeparator();
menuHelp->addAction(actionAbout);

if(tab) tab->addOtherActions(menuBar());

menuBar()->addMenu(menuHelp);

ui_toolBar->addAction(actionNew);
ui_toolBar->addAction(actionOpen);
if(tab) tab->addToolbarActions(ui_toolBar);
}

为它提供了一个标签,该标签也可以使用这些功能将自己的操作添加到菜单中.

It is supplied a tab, which can add its own actions to the menu as well using those functions.

推荐答案

这是Mac OS X的一项功能,不容易禁用.您会注意到,Mac OS上几乎所有应用程序都具有它.操作系统会自动将其添加到编辑"菜单中,以允许输入国际字符.

This is a feature of Mac OS X that isn't easily disabled. You'll notice that nearly every application on Mac OS has it. It's automatically added to the Edit menu by the OS to allow the input of international characters.

从您的问题看来,但并不是很清楚,当您最初创建编辑"菜单时,特殊字符..."菜单项最初是最后一个菜单项,但是一旦成为editMenu->clear(),它便成为第一个菜单项.已被调用.您可以选择的一种方法是代替clear()菜单,您可以delete菜单并完全重新创建它们.但是,您的编辑菜单看起来非常静态.也许根本不需要重新创建它.

It seems from your question, but isn't quite clear, that when you initially create the Edit menu, the Special Characters... menu item is initially the last menu item, but becomes the first menu item once editMenu->clear() has been called. One route you could go is instead of clear()ing the menus, you can delete the menus and recreate them completely. Your edit menu looks pretty static, though. Maybe it doesn't have to be recreated at all.

现在,这就是说,如果您确实确定需要摆脱此菜单项,则有两种方法可以实现此目的.

Now, that said, if you're really sure you need to get rid of this menu item, there are a couple of ways to accomplish that.

第一个也是最不希望使用的方法是完全没有编辑"菜单.如果没有标题为编辑"的菜单,Mac OS将不会添加特殊字符"菜单项.

The first, and least desirable one is to simply not have an "Edit" menu. If there's no menu titled "Edit", Mac OS will not add a "Special Characters" menu item.

第二种方法需要一些平台特定的Objective-C代码.显然,这仅应内置到Mac OS上的项目中.

The second method requires a little platform specific Objective-C code. Obviously, this should only be built into your project on Mac OS.

MenuDeleter.m:

MenuDeleter.m:

#include <Foundation/NSUserDefaults.h>

void deleteSpecialCharacters()
{
    [[NSUserDefaults standardUserDefaults]
        setBool:YES forKey:@"NSDisabledCharacterPaletteMenuItem"];
}

MenuDeleter.h

MenuDeleter.h

#ifndef MENUDELETER_H_
#define MENUDELETER_H_

void deleteSpecialCharacters();

#endif

最后,在main.cpp中:

And finally, in main.cpp:

#include <QApplicaiton>
#include "MenuDeleter.h"

int main(int argc, char **argv)
{
#ifdef Q_OS_MAC
    deleteSpecialCharacters();
#endif
    QApplication app(argc, argv);
    ....
    return app.exec();
}

这就是使它完全消失的方法.但是问题是,您是否真的要阻止用户将特殊字符输入到您的应用程序中?

So that's how to make it go away completely. But the question is, do you really want to prevent the user from being able to input special characters into your app?

这篇关于Qt Mac(重新)移动“特殊字符..."编辑菜单中的操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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