views:

724

answers:

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 a 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.

A: 

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
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.
Max Howell
A: 

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
This won't remove the space next to the Menu with the Windows style.
Max Howell
+1  A: 

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