在Qt中,对于上下文菜单项,如何隐藏图标的空间
我正在使用 QAction
为小部件添加上下文菜单。 现在,操作文本旁边有一些空白。 我认为这是 QIcon
与 QAction
关联应该存在的空间。 现在我该如何隐藏这个空间。 我尝试这样做:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你没说是哪个平台。 但在 Mac 上,您可以通过以下方式完全关闭菜单项:
You don't say which platform. But on Mac you can turn off menu items altogether with:
我不知道是否有特定于操作或菜单的方法,但您可能可以使用样式将其删除。
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.
您没有提到您正在使用的 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)