在Qt中,对于上下文菜单项,如何隐藏图标的空间

发布于 2024-07-07 13:51:06 字数 257 浏览 8 评论 0原文

我正在使用 QAction 为小部件添加上下文菜单。 现在,操作文本旁边有一些空白。 我认为这是 QIconQAction 关联应该存在的空间。 现在我该如何隐藏这个空间。 我尝试这样做:

action->setIcon(QIcon());

但似乎仍然不起作用。

如果您有办法删除文本前的空格,请告诉我。

I am adding a context menu using QAction for a widget.
Now, there is some white space beside the text of the action. I assume this is the space where the QIcon association with the QAction should have been there. Now how do I hide this space. I tried doing:

action->setIcon(QIcon());

but still does not seem to work.

Kindly let me know if you have the way to remove that space before the text.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

凉城 2024-07-14 13:51:06

你没说是哪个平台。 但在 Mac 上,您可以通过以下方式完全关闭菜单项:

qt_mac_set_menubar_icons( false );

You don't say which platform. But on Mac you can turn off menu items altogether with:

qt_mac_set_menubar_icons( false );
甜点 2024-07-14 13:51:06

我不知道是否有特定于操作或菜单的方法,但您可能可以使用样式将其删除。

I don't know if there is a way specific to the action or the menu, but you could probably remove it using a style.

孤檠 2024-07-14 13:51:06

您没有提到您正在使用的 Qt 版本,但 4.4.3 版本的 QAction 允许您隐藏图标:
http://doc.trolltech.com/4.4/qaction.html#iconVisibleInMenu-道具

您还可以尝试使用 QAction::QAction ( const QString & text, QObject *parent ) 构造函数:
http://doc.trolltech.com/4.4/qaction.html#QAction- 2 (4.4.3)
http://doc.trolltech.com/4.0/qaction.html#QAction- 2 (4.0)
http://doc.trolltech.com/3.3/qaction.html#QAction- 2 (3.3)

You didn't mention the version of Qt you are using but version 4.4.3's QAction allows you to hide the icon:
http://doc.trolltech.com/4.4/qaction.html#iconVisibleInMenu-prop

You can also try using the QAction::QAction ( const QString & text, QObject * parent ) constructor:
http://doc.trolltech.com/4.4/qaction.html#QAction-2 (4.4.3)
http://doc.trolltech.com/4.0/qaction.html#QAction-2 (4.0)
http://doc.trolltech.com/3.3/qaction.html#QAction-2 (3.3)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文