Menu options not visible after tapping on one of the menu option - uimenucontroller

I am not able to show other menus on tapping a particular menu option.
The behavior which I want is similar to the default cut-copy menu options that is: When I long press in UITextView area, I get select,select all and other menus. If I tap on select all, immediately i see copy, paste options.
Similar in my app, I have an image on the screen. When I long press the image, I get delete menu. When i tap on delete I should get really delete, cancel menu options.
I am not able to show really delete, cancel options.
Is there any way to do this.
I have come across update method of UIMenucontroller. But don't know how to use it.

Try this it works.
In your menu item click event, add notification for UIMenuHideNotification and in its handler write follwoing code
- (void)didHide:(NSNotification *)notif {
UIMenuController *mc = [UIMenuController sharedMenuController];
dispatch_async(dispatch_get_global_queue(0,0), ^{
dispatch_async(dispatch_get_main_queue(), ^{
//create a new menu items add it to mc and display it///
[mc setMenuVisible:YES animated:YES];
});
});
}

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();
}

Add functions to the Main Menu at the top of a window

I would like to add sub options to the Main Menu at the top of a main frame window in MFC.
For example; File>Open, or Edit>Undo.
Is this possible to do at all? My intention is to replace the function of some buttons in my program with options typically found in the drop down menus
Also after adding an item to the Main Menu how would you use it to call a function?
Here I have added an entry to the View menu called Test:
When I build and runt he program it shows disabled:
This is because I still have to create an event handler. In the resource editor you right-click the menu item and select Add Event handler:
This brings up the class wizard:
On the dialogue there are a couple of menu event handlers to choose from. Select the one you need (as in the screen shot) but don't forget to choose the right class on the right. Then click Add and Edit.
Now you can add your event handler functionality. Example:
void CMainFrame::OnViewTest()
{
AfxMessageBox(_T("Hello!"), MB_OK | MB_ICONINFORMATION);
}
When I compile and run this:
Hopefully this will help you get up and running.

How to change the default QPushButton in a QDialogBox

My goal is to have two buttons, "Cancel" and "Connect", and to have Cancel be the default button when the user presses ENTER. I also want the user to be able to TAB to the next button ("Connect") and press ENTER and have "Connect" get pushed. Here's my code:
QPushButton * cancelButton = new QPushButton(tr("&Cancel"));
cancelButton->setAutoDefault(true);
cancelButton->setDefault(true);
cancelButton->setFocus();
QPushButton * continueButton = new QPushButton(tr("Co&nnect"));
continueButton->setAutoDefault(true);
continueButton->setDefault(false);
ui->buttonBox->addButton(cancelButton, QDialogButtonBox::RejectRole);
ui->buttonBox->addButton(continueButton, QDialogButtonBox::AcceptRole);
Setting the Cancel button to the the default button doesn't actually seem to work.
Setting the autoDefault property on all the butons seems to be necessary in allow the buttons to get pushed after pressing TAB and ENTER for example. This seems to jive with the documentation for autoDefault. However, the documentation for the default property seems to indicate that the default button will get pushed only if there are no buttons that have the autoDefault property set. Otherwise, the button that gets pushed when ENTER is pressed will be the currently selected autoDefault button. So it seems like what I need to do is to make the cancelButton have focus by default, but I can't seem to figure out how to do this.
You have to call cancelButton->setFocus(); after adding the buttons to the QDialogButtonBox, not before.
Try adding below line before you call dialog->show
button->isEnabled(true)

QMessageBox addButton() using standard icon/display

I'm trying to make our popup messages boxes have more appropriate text, rather than the generic "Ok", "Cancel", etc. However, I don't see an easy way to get the standard icons on the buttons.
For example, normally the QMessageBox::Save button has an icon with it. Instead I want the text to be "Save Part", but since this is still essentially a save operation it'd be nice to have the same icon.
I'd be happy to have this tied to the Role, as all my custom test buttons map to one of the standard roles. Is there any easy way to get the standard icons onto the custom buttons?
If you just want to change the text on the StandardButton but keep the standard icon you can do the following:
QMessageBox *box = new QMessageBox("title", "text", QMessageBox::NoIcon, QMessageBox::Save, QMessageBox::Close, QMessageBox::Open);
box->button(QMessageBox::Save)->setText("Save part");
box->show();
This will result in following:
And the button will keep the same role
Add a button with QMessageBox::addButton to QMessageBox, then call the Button's setIcon with the icon returned by the QStyle::standardIcon you want.

"Sticky" MFC popup menu

I currently have some toolbar buttons with a small arrow on the side (TBSTYLE_EX_DRAWDDARROWS) that, when clicked, result in a popup context menu being displayed under the button. This is done by constructing a custom popup menu and calling TrackPopupMenu.
The client now wants to be able to select multiple options from the menu before it closes, so that multiple options can be be modified without the need to re-open the menu and wait for an intermediate redraw between each change.
For example:
User clicks dropdown button
Dropdown menu appears (modal, waits indefinitely for user action)
User clicks some item (e.g., toggle a checkmark)
Timer (e.g., 500ms) starts
If timer expires, the menu is closed and all selected actions are executed.
User clicks another item before the timer expires, go back to 4.
The best I can come up with is to redisplay the menu by calling TrackPopupMenu multiple times. This makes the menu "flicker" when you select an item, and will probably require me to start a thread in order to do the timeouts, which I would rather avoid.
Rather than a menu, put up a dialog box with the options on it. A dialog can easily do all that is required.
A menu that doesn't close when you click it will just seem wrong. A dialog that closes by itself will seem wrong too, but it's probably the least of two evils.
Edit: If there's anything I've learned with Microsoft, it's don't try to fight the default behavior. You're asking for trouble if you do.
If you're building your menu dynamically I can see how automatic sizing can be handy, but it's not hard to do in a dialog either - make the dialog really big and before it becomes visible, enumerate the children and take a union of all their rectangles, then resize to that. Checking the boundaries to make sure they're on-screen is just a few if statements with OffsetRect. Checkboxes are trivial; icons less so, but still not bad.
One additional enhancement that would be easy to add is to dismiss the dialog immediately on a double-click.
Following #Mark Ransom's answer, you should put up a dialog box. But you can make the dialog modeless and make it close itself when you click outside of it (i.e., the dialog loses focus). That way it could behave more like a menu.
Notice that normal menus never go away by themselves, you always have to click somewhere outside the menu (or one of its options) to make it disappear.