PDA

View Full Version : Disable popup menu



febil
25th March 2009, 14:17
Hi all,
Can the popup menu be disabled in QMenu item using QT. Thats is, i have a menu named "File". But the sub menus like "Open, Close" etc not needed. I need to perform some operations on clicking "File" menu.
Plz help.

Hiker Hauk
25th March 2009, 17:23
This is how you add a File menu,

fileMenu = menuBar()->addMenu(tr("&File"));

This is how you add a File action,

menuBar()->addAction(fileAct);

where fileAct is a normal action.


However, this is strange behaviour.

Either you only add actions to the menubar and no menu, or you use a toolbar instead.

drhex
25th March 2009, 17:56
I presume that Open and Close are menu items rather than submenus. When you added them to the QMenu, the return value was a QAction *. Call QAction::setEnabled(false) on those, to have them grayed out.

febil
26th March 2009, 04:12
Thnx for the replies.
if SetEnabled() is used, the action is disabled. Then it is not possible to do any operations on clicking the QMenu. I need to do some operations on QMenu click. No need to show the action items.
Plz suggest...

talk2amulya
26th March 2009, 06:19
i m not sure about this, but what happens if u call setVisible(false) on you File menu..since its a QWidget, i believe it wont show..

febil
26th March 2009, 07:20
in this case, the Action will not be displayed. But cannot do any operation on clicking QMenu.
I did a solution as: handled mousePressEvent/mouseReleaseEvent in a derived class of QMenu. Then i can perform the operation in menu click and no action needed here. But still i have a problem that the selection and focus is still in menu. So if i need to click another button i need to click it twice. I am not sure how to remove the selection and focus from menu. :(

talk2amulya
26th March 2009, 07:29
umm, how about setFocusPolicy(Qt::NoFocus)..but then it'll never have the focus..is that how you want it?

febil
26th March 2009, 12:21
i have found a solution:: send MouseButtonPress event in Release event.

{
QMouseEvent Event(QEvent::MouseButtonPress, pos(), Qt::LeftButton, 0, 0);
QApplication::sendEvent(this, &Event);
}
Now it is working.......