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.
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.
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.
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.
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...
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..
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.![]()
umm, how about setFocusPolicy(Qt::NoFocus)..but then it'll never have the focus..is that how you want it?
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.......
Bookmarks