Closing an expanded menu in qt - c++

I have a menu and it has a number of menu items. Usually when menu is clicked it expands. But in some situations when the menu is clicked its action need to be fired but menu should not be expanded. How can we do this in qt?

Related

Is there a way to stop a qmenu from being hidden when you click off of the menu

I have a QMenu. I would like to keep the menu up when you click outside menu. Is this possible. I have tried overriding the eventmethod but that does not work. I know how to keep the menu open when you click on an action (there are a few questions here about that) but I want to keep it up when you click outside the menu, clicking on an action should still close the menu. This should work when bringing up the menu via popup or exec. Is this possible using QMenu?
EDIT: showTearOffMenu is not what I want, I would like to keep these pop-up frameless
EDIT #2: Overriding closeEvent and ignoring it will keep the menu up but now it steals all clicks
void MenuSubclass::closeEvent(QCloseEvent* e){
e->ignore();
}

How to set signal to a button of the GtkColorChooserDialog composite widget?

I am using Glade to create GUI. I have the default GtkColorChooserDialog.
How to set signals to the Select and Cancel button clicked event.
These two buttons are grouped in one GtkButtonBox and I can only choose the box, but not the buttons themselves.
If I can't select the button then how to assign action to the clicked signal?

Gtk2: event for top menu item click?

I want to see how to make it in Gtk2 (e.g. C++). Does gtk2 has ability to set event which is called, when top menu item is clicked?
E.g. topmenu may be "File Edit Help". When "Edit" clicked (Alt+E key too) I want that event is called (event sets checkmarks for menu items in Edit).
How to do it.
You can "trap" them with activate-current. As most of the widgets, they have an activated signal handler.

System Tray Menu error MFC

I am Making an Application which will make a dialog as system tray icon after some button press. it is working fine but also i need to open the menu same as dialog contains on Right Click and have written following Code:
CMenu pMenu;
pMenu.LoadMenu(IDR_MENU1);
POINT pointCursor;
::GetCursorPos( &pointCursor );
pMenu.TrackPopupMenu(TPM_BOTTOMALIGN|TPM_LEFTBUTTON|TPM_RIGHTBUTTON, pointCursor.x, pointCursor.y, this);
It is Creating the menu but the width of the menu is very thin as shown following:(Yellow highlighted area is menu)
if I add only first submenu of main menu then it works well as following code:
CMenu *pMenu = GetMenu();
POINT pointCursor;
CMenu *pMenu = GetMenu();
::GetCursorPos( &pointCursor );
pMenu->GetSubMenu(0)->TrackPopupMenu(TPM_BOTTOMALIGN|TPM_LEFTBUTTON|TPM_RIGHTBUTTON,pointCursor.x,pointCursor.y,this);
On applying this code i get following output
Actually I need the Following menu:
Kindly Suggest Where i am doing it wrong
TrackPopupMenu cannot display the menu bar as part of it's work. The menu bar itself is not displayed because TrackPopupMenu requires a handle to a menu, submenu, or shortcut menu. So, given that, if you really want the same menu structure including the menu bar you've shown, you'll need to create that structure dynamically using CMenu methods. Or, simply create a new menu resource with a different name that includes the menu bar items as submenus.

Creating popup menu in Qt for QTableView

I have a QTableView in the main UI of my program. I'd like to show popup menu when user right clicks on the cells of the table and take appropriate action when an option is selected from the menu.
I am using Qt Creator 1 (Qt version 4.5). How can I do that?
Check out the customContextMenuRequested signal to get the event, and use a QMenu for the menu itself. Use QTableView::indexAt to find out what, if any, cell was clicked based on the coordinates given to the signal and take the appropriate action when a menu item is clicked.