I have qwebengine that i have overwritten its context menu with a custom pop up menu and i am need to add menu item that when i right click a url it gives me the option to open in new tab, how i can achieve this? I have no idea how to do it so i have no code to show and there isn't enough topics out there but in qt simple broswer they have the below code but it's not understood for me as i never worked with qt here is the example:
void WebView::contextMenuEvent(QContextMenuEvent *event)
{
QMenu *menu = page()->createStandardContextMenu();
const QList<QAction*> actions = menu->actions();
auto it = std::find(actions.cbegin(), actions.cend(), page()->action(QWebEnginePage::OpenLinkInThisWindow));
if (it != actions.cend()) {
(*it)->setText(tr("Open Link in This Tab"));
++it;
QAction *before(it == actions.cend() ? nullptr : *it);
menu->insertAction(before, page()->action(QWebEnginePage::OpenLinkInNewWindow));
menu->insertAction(before, page()->action(QWebEnginePage::OpenLinkInNewTab));
}
menu->popup(event->globalPos());
}
If someone can explain the above code and provide simple snippet on how i can achieve it in pyqt, I would be so thankful.
self.yourWidget_qwebengine.contextMenuEvent=self.mycontextMenuEvent
def mycontextMenuEvent(self, event):
menu = QtWidgets.QMenu(self)
oneAction = menu.addAction("&Open New Tab")
twoAction = menu.addAction("O&pen in New Window")
menu.exec_(event.globalPos())
Adding this simple code might help if you have overwritten context menu event
If a link was right-clicked, use the following snippet to get the address:
self.page().contextMenuData().linkUrl()
where self is a QWebEngineView. You can call isEmpty() on the url to test whether it was actually a link that was right-clicked.
Related
Is there any way to open a custom screen, as placed in the Acumatica menu in the Site map, as a popup (not a new tab) so that it doesn't occupy the existing browser?
I've tried using this, which works ok:
var url = "http://localhost/AcumaticaDB2562/?ScreenId=AC302000&&OpenSourceName=Bills+and+Adjustments&DataID=" + apinvoice.RefNbr;
throw new PXRedirectToUrlException(url, "Open Source")
{
Mode = PXBaseRedirectException.WindowMode.NewWindow
};
The problem is, I don't want the lefthand menu to show up. I just want the screen without any navigation. Is this possible?
I like to use PXRedirectHelper.TryRedirect for calling other graphs. The WindowMode tells the framework how to open the graph. For your question, you will want to use WindowMode.NewWindow as shown in the example below:
var graph = PXGraph.CreateInstance<MyGraph>();
PXRedirectHelper.TryRedirect(graph, PXRedirectHelper.WindowMode.NewWindow);
The enum values for WindowMode are: InLineWindow, New, NewWindow, PopUp, Same.
Alternatively you could do something like this...
throw new PXRedirectRequiredException(graph, true, string.Empty) { Mode = PXBaseRedirectException.WindowMode.NewWindow };
I have a problem with my VSTO addin for excel.
I tried creating custom task pane fot my addin. However, when I tried to deploy it on a screen with different resolution from the developer's monitor, the addin does not automatically fits the screen. Note: my clients have different screen resolution.
On my vsto project, i tried to create a custom user control, and attach it on the excel pane.
Please see my code below:
private void btnDownload_Click(object sender, RibbonControlEventArgs e)
{
taskPaneView = new ucCusipAddPanel();
if (myTaskPane == null)
{
myTaskPane = Globals.ThisAddIn.CustomTaskPanes.Add(taskPaneView, "My Custom Task Pane");
myTaskPane.DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionRight;
myTaskPane.DockPositionRestrict = Office.MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoChange;
myTaskPane.Visible = true;
myTaskPane.Width = 303;
}
else
{
myTaskPane.Visible = true;
taskPaneView.BringToFront();
taskPaneView.Focus();
}
}
ucCusipAddPanel is the name of my user control.
This is how invoke my custom taskpane upon ribbon button click. I already set the AutoSize property to true of my user control however still the problem exists.
How could I resolve this?
Thank you in advance.
You need to play with the AutoScaleMode of the myTaskPane object.
I think the correct solution is to use: myTaskPane.AutoScaleMode = AutoScaleMode.Dpi;
see MSDN
I've got a strange behavior when showing a ContentDialog. When the dialog is on screen and I drag the StatusBar down, the dialog disappears.
private ContentDialog _connectivityDialog = new ContentDialog { IsPrimaryButtonEnabled = false, IsSecondaryButtonEnabled = false, Title = "Test"};
Somewhere I just call _connectivityDialog.ShowAsync();
I made a simple project to reprduce this behavior:
https://www.dropbox.com/sh/0a6ad5xtrzii7sx/AADnbF9TGpfJnV9xnVG4FQMJa?dl=0
Any idea why this happens?
I found the solution while investigating for another problem:
BackButton dismisses the dialog.
Solution:
_connectivityDialog.Closing += (sender, args) =>
{
args.Cancel = true;
};
But be aware that the Hide()-Method is also affected. You can do a workaround like on this post:
How to prevent the ContentDialog from closing when home key is pressed in Windows phone 8.1..?
I want to be able to go to options menu in the game I am developing and set up my controls.
It is a simple game of pong (for now) and the controls for each player are just up and down.
This is how I want the process to look like: I click SETUP CONTROLS, game displays the name of the control I am supposed to change and it waits, I click the button on keyboard that i want it to be changed to, game reads it and displays the next control I am supposed to change and so on until i change all controls.
I have found a way how to do that here and my code now looks basicly like this:
if (optionsBList.IsButtonClicked("SETUP CONTROLS")) //when i click the
//SETUP CONTROLS button
//in the options menu
{
KeyboardState currentKeyboardState = new KeyboardState();
waitingForKey = true;
while (waitingForKey)
{
if(currentKeyboardState.GetPressedKeys().Count() > 0)
{
player1.upkey = currentKeyboardState.GetPressedKeys()[0];
//the path for the key isn't player1.upkey, but lets say it is.
waitingForKey = false;
}
}
}
In this short code my goal is to change just one key. If I can make it change 1 key, changing more wont be a problem.
The problem is, I don't see why does my game stop responding when i click the SETUP CONTROLS button. I don't see an infinite loop here nor a memory leak.
Why is my game crashing and is there a better way to load controls in options menu?
If you saw the answer from the link you placed in your question, you would have noticed that he actually deleted the while loop and he made it an if statement.
Like Nico Schertler said : "while(waitingForKey) is your infinite loop. That loop blocks the game thread, so no further input is recognized."
Link to the answer from your link: https://stackoverflow.com/a/15935732/3239917
if (optionsBList.IsButtonClicked("SETUP CONTROLS")) //when i click the
//SETUP CONTROLS button
//in the options menu
{
KeyboardState currentKeyboardState = new KeyboardState();
waitingForKey = true;
if (waitingForKey )
{
if(currentKeyboardState.GetPressedKeys().Count() > 0)
{
player1.upkey = currentKeyboardState.GetPressedKeys()[0];
//the path for the key isn't player1.upkey, but lets say it is.
waitingForKey = false;
}
}
}
I'm new to JavaFX. I want to create Listener which calls question dialog when user closes a tab into the TabPane. So far I managed to create tabs dynamically and add some custom configuration.
tabAvLabel = new Label(ss);
tabPane.getTabs().add(0, tab); // Place the new tab always first
tabPane.getSelectionModel().select(tab); // Always show the new tab
tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.ALL_TABS); // Add close button to all new tabs
I don't know what event listener I need to use and how to define it. Would you show me how to implement this?
You can try onCloseRequest for Tab class
tab.setOnCloseRequest(new EventHandler<Event>()
{
#Override
public void handle(Event arg0)
{
//your code
}
});
Try this code :
tabAvLabel = new Label(ss);
tabPane.getTabs().add(0, tab); // Place the new tab always first
tabPane.getSelectionModel().select(tab); // Always show the new tab
tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.ALL_TABS); // Add close button to all new tabs
tabPane.getOnClosed(), setOnClosed(new EventHandler<Event>(){
#Override void handle(Event e){
// What you have to do here
}
})
For more information, see http://docs.oracle.com/javafx/2/api/javafx/scene/control/Tab.html#onClosedProperty
I've hacked a similar support you have in jdk8 support into 2.2 (https://git.eclipse.org/c/efxclipse/org.eclipse.efxclipse.git/tree/bundles/runtime/org.eclipse.fx.e4.controls.fx2/src/org/eclipse/fx/e4/controls/fx2)
The answer of #VagrantAI can work. But you have to add the following codes on your 'OK' button click action function:
stage.fireEvent(
new WindowEvent(
stage,
WindowEvent.WINDOW_CLOSE_REQUEST
)
);
While the problem of this approach is the event is triggered when you click 'X' to close the window too. This should not be the purpose normally.
To solve this, add a flag (or static variable) in the class that loads the window. So every time the window is loaded, set the flag to false. When the window is closed, set the flag only when the 'OK' button is clicked. Then you can do your action regarding the value of this flag.