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
Swiftui Pick a Value from a List with Ontap Gesture
Xcode 9 Fails to Build Swift 4 Project with Pod
Saving Dictionary into Nsuserdefaults
Swift Spritekit Arc for Dummies
Swift: Dictionaries Inside Array
Text from [String] to a Label.Text Isn't Working the First Time
How to Convert a Unsafemutablepointer<Void> to Uint8
Swift Protocol Property in Protocol - Candidate Has Non-Matching Type
How to Call a Method on a Uiview from Outside the Uiviewrepresentable in Swiftui
Connecting Hc-05 with iPhone Se iOS(V11.0)
Error with Parse Query Findobjectsinbackgroundwithblock
How to Make a Custom Mkannotationview with Xib
Why Does Somestruct() Is Anyobject Return True
Data Ranged Subscribe Strange Behavior