3

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.

NG_
  • 6,895
  • 7
  • 45
  • 67
AMM
  • 17,130
  • 24
  • 65
  • 77

3 Answers3

1

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

qt_mac_set_menubar_icons( false );
Andy Brice
  • 2,297
  • 1
  • 21
  • 28
0

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.

Caleb Huitt - cjhuitt
  • 14,785
  • 3
  • 42
  • 49
  • Indeed, I just looked through the sources, this is the only easy way to do it. Though reimplementing styles is not fun. QWindowsStyle, QWindowsXpStyle, QMacStyle, QGtkStyle, QPlastiqueStyle, etc. – mxcl Oct 21 '08 at 13:06
-1

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)

Chris Roland
  • 777
  • 3
  • 9