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.
Related
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?
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.
In MFC featurepack i create a standard menu and set the ID of sub menu to the same command of toolbar button to take that button's image that toolbar is the one sent to this method
CMFCToolBar::AddToolBarForImageCollection
and also I use the
GetContextMenuManager()->AddMenu(L"Mymenu", IDR_ContextMenu1);
in the application and
theApp.GetContextMenuManager()->ShowPopupMenu(IDR_ContextMenu1,rect.left,rect.top,button);
in the show menu event
I need to know how to add a menu item with a specified icon at the run-time dynamically
See the documentation about OnInitMenuPopup of your CMainFrame.
Hi I am new to Mac using wxWidget.
I need to add a sub menu and some menu items under the Window Menu on MAC.
I am able to do same for Window menu on PC but not on MAC.
Also, I am not getting event for click on Window Menu to the function attached with EVT_MENU_OPEN event.
Please help.
I don't really understand the question clearly. However you may have to do something like this for a menu on mac.
m_menuBar = new wxMenuBar();
#if defined(__WXMAC__)
m_menuBar->SetAppleMenuItemLabel(wxApp::s_macAboutMenuItemId, wxT("About"));
m_menuBar->SetAppleMenuItemLabel(wxApp::s_macWindowMenuItemId, wxT("Window"));
m_menuBar->SetAppleMenuItemLabel(wxApp::s_macExitMenuItemId, wxT("Quit"));
#endif
where s_macAboutMenuItemId, s_macWindowMenuItemId, s_macExitMenuItemId are your respective menu ids defined.
and regarding not getting event for click on Window Menu to the function attached with EVT_MENU_OPEN event, check if you have correct entries(Menu id, corresponding function name) in the declared event table.
I'm building a small program in Qt with menu bars (menuBar) using C++ and I would like to know how to gray out (eg. disable) an item of the menu when a certain variable is activated. Is it possible?
If you know an index of the corresponding QAction :
QMenu::actions.at(i).setEnabled(false);
P.S. As kindly prompted below, setEnabled(bool) and setDisabled(bool) are slots (so is toggle()), so they can be connected to a signal indicating a need to change the availability of the action.
Looking for the index of the action is not necessarily convenient. If you have built the interface with QtCreator's form editor then you will have an action for each menu item. Their names are based on the text that you first give to the actions. For example if you interactively enter a menu item with title Foo Bar then an action named actionFoo_Bar is created for you. Just type ui->action in the code editor and watch what "name completion" QtCreator will propose.
In such a case I would consider a call like this:
ui->actionFoo_Bar.setEnabled(false);
You can even make the menu item disappear with
ui->actionFoo_Bar.setVisible(false);