I develop a tree view and implement context menus for its items. Right click an item, its context menu pops up. Right click an other item, the old context menu disappears but the new menu doesn't appear. Another right click is required to show the new context menu. Any way to make one right click works in this case? My code to generate the context menu is as below
void MyTreeView::contextMenuEvent(QContextMenuEvent* event) override
{
if (Item* item = itemAt(event->pos())) {
unique_ptr<QMenu> menu(item->createMenu(this));
if (menu && !menu->isEmpty())
menu->exec(event->globalPos());
}
}
Related
I am trying to change a button in the side menu drawer, depening on whether the user is logged in or not. I hoped I could simply just check everytime the side menu is opened via the burger icon by overriding OnAppearing():
protected override void OnAppearing()
{
base.OnAppearing();
SetButtonAccordingToPosition();
}
Unfortunately, this function is only called ONCE when the app starts and then never again anymore.
I need to find out when the side menu is visible. How would i do that?
I'm having a requirement where I click a button then I need to initialise the tab and its children, and also I need to push a new page on top of this, which shouldn't show the tabs below, and when I press back it should go back to the previous tabbed page with the children being active from where I navigated from
I know that I can do this by
CurrentPage = Children[2];
This would give me the result of navigating to the specific child of a tabbed page, but how can I navigate to a page further is something I'm not able to figure out
The design of my app requires that I have a button in the Flyout Header, a separate view, which navigates to a page
Unlike the flyout items themselves though, when I click on the button, the page loads under the flyout header which stays open
Is there a way to have a button mimic exactly what happens when navigating within the flyout contents themselves?
The page I'm trying to navigate to is registered as a route in AppShell
The code in the view referenced in FlyoutHeader calls it from the button click like so
await Shell.Current.GoToAsync("thepage");
As mentioned above the flyout menu is open at this point in order to access the button but when clicked it loads the desired page but I want it to automatically shut the menu
Is there a way to do this please?
As Ricardo says above.
You can use Shell.Current.FlyoutIsPresented = false;
//===event click or command===
private async void Button_Clicked(object sender, System.EventArgs e)
{
await Shell.Current.GoToAsync($"your others pages route");
Shell.Current.FlyoutIsPresented = false;
}
I show context menu when user right clicks on row at TableView and select clicked item:
downloadContextMenu.popup()
tableView.selection.clear()
tableView.selection.select(row)
but TableView show selection only if I will move mouse to something else (i.e. button) after it. So, how to update TableView in this case?
downloadContextMenu is Menu
P.S. If I will do it by this:
tableView.selection.clear()
tableView.selection.select(row)
downloadContextMenu.popup()
I will have the same problem, but after next opening of context menu (open menu, then click outside to close it, then open again)
I managed to create a context menu that gets activated after a right click on each item of a QTreeWidget tree:
contextMenu = new QMenu(ui->treeWidget);
ui->treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
addElement = new QAction("Add Element",contextMenu);
deleteElement = new QAction("Delete Element",contextMenu);
ui->treeWidget->addAction(addElement);
ui->treeWidget->addAction(deleteElement);
connect(addElement, SIGNAL(triggered()), this, SLOT(addElementHandler()));
connect(deleteElement, SIGNAL(triggered()), this, SLOT(deleteElementHandler()));
My intention is to add new items under another in the tree or delete them by right clicking on a specific item using this context menu.
However I'm not sure how to realize from the handlers on exactly which item of the tree the right click was made.
Could you please give me a clue?
Thanks in advance!
If you are not going to change the TreeWidget selection behavior or set the current item by your own - you can use just the native behavior. While context menu requesting the tree selects the item, on which the right click was performed and that is the currentItem. So in addElementHandler slot the currentItem() will give you exact item you want.