How Set Custom Fonts for iOS13 Context Menu Actions

Context Menu selection color and frame size Swift 5 iOS 13

I came across the same struggle today and I found a solution that worked for me, so I hope it's relevant for you as well.

I found the solution in this post: https://kylebashour.com/posts/context-menu-guide

If you scroll down to the section: UITargetedPreview, there's an example for a UITableView however you can apply the same solution for the UICollectionView :)

Qt shortcut for custom context menu

Thanks to Scheff's hint I got it working. I do not now if this is really the correct way but this works for me.

The action needs to be declared in the constructor of your GUI class (e.g. MainWindow):

actionDel = new QAction(tr("delete"), this);
actionDel->setShortcut(QKeySequence(Qt::Key_Delete));
connect(actionDel, SIGNAL(triggered()), this, SLOT(actionDel_triggered()));

The triggered signal needs to be connected to a slot. Hint: if you create the slot do not use on_ACTIONNAME_triggered, this will interfere with the designer and cause a connection error.

Next add the action to a custom menu

fileContextMenu = new QMenu(this);
fileContextMenu->addAction(actionDel);

And to the widget

ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->treeView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showDirContextMenu(QPoint)));
ui->treeView->addAction(actionDel);

All in the constructor of your GUI class.

To show the context menu use the following code in slot used in the above connect:

QModelIndex index=ui->treeView->indexAt(pos);

// Here you can modify the menu e.g. disabling certain actions

QAction* selectedItem = fileContextMenu->exec(ui->treeView->viewport()->mapToGlobal(pos));

If you do not have a slot for an action, the action can be also handled in the context menu slot, but this does not work with shortcuts!

if(selectedItem == actionOpen){
on_treeView_doubleClicked(index);
}


Related Topics



Leave a reply



Submit