How to open "external link" by clicking a menu item? - qt

I need to open some link (in my default browser) in a way similar to setOpenExternalLink on Qlabel, but by clicking on an item in the menu.
Is there some simple way?
I think about using Qlabel with required link and use some action/event to pretend the click on it, meanwile the Qlabel was hidden.

Upon clicking the specific menu item (handled using your standard signals and slots) you could use openUrl(const QUrl &url) of QDesktopServices to have that link launch in your default browser.
As the documentation states, it will open
...the given url in the appropriate Web browser for the user's desktop environment, and returns true if successful; otherwise returns false.
So no need for fancy tricks with QLabels and the like.

Related

Qt Installer Framework : Hide the Back button

How to Hide the Back Button in Qt installer framework?
Please see attached image.
See my answer to Qt installer framework hide or disable buttons quoted below:
For the wizard BackButton specifically, it automatically disables itself if there are no pages before the current page a la the Introduction page.
From QtScript this can be accomplished by removing any dynamic pages before the current page with installer.removeWizardPage and disabling all default pages before the current page with installer.setDefaultPageVisible(QInstaller.Introduction, false).
There is void QWizard::setButton ( WizardButton which, QAbstractButton * button ) what means you schould be able to set a button which behaves like you need it. Derive a Class from QAbstractButton. Reimplement the paintEvent() to paint nothing and reimplement the mouseEvents to do nothing. That should do the (dirty) trick. Even if the wizard sets it to be visible, it won't draw itself and can't digest and mouse actions. Just tested it ... should work for you.

Qt Popup as a completer window

I need to make some kind of popup window that contains propositions to complete sentences in text editor (QTextPlainEdit). This window needs to be on top of all windows of this application. Also this popup mustn't interrupt typing in the text editor when it appears. I tried different types of flags for QWidget that implements this completer but all I have got is that this completer window is placed above all windows of OS (even if this application is not active) or it interrupts typing in the text editor and makes main window not active any time it appears.
What flags should I use for completer widget?
You could try to use QWidget::setWindowFlags(Qt::Window | Qt::FramelessWindowHint).
Otherwise you could use a customized version of Qt::Popup, by overriding the automatic closing behavior.
You could also try this: if you set the QTextPlainEdit's parent as the completer's parent it should do what you want, provided that the parent does not have a layout (otherwise it will not "float").
The Qt docs contain an example that implements a google-based auto-completer widget, here: http://qt-project.org/doc/qt-4.8/network-googlesuggest.html.
As far as I can tell, they do two things that might be relevant to your situation. One is the flags they set on the popup widget:
popup = new QTreeWidget;
popup->setWindowFlags(Qt::Popup);
popup->setFocusPolicy(Qt::NoFocus);
popup->setFocusProxy(parent);
The other is a custom event filter on the popup widget, which forwards most keypress-events to the editor widget, and closes the auto-completer on Enter or Escape.

how to se t the right click operations of a link in qtwebkit

How to edit QtWebKit's right-click context menu in Qt Creator?
how to get response in QtWebKit
https://qt-project.org/forums/viewthread/15149/
i have seen all these threads and more but cant get my anwser
i want to set the righ click menu of links images frames etc. in qtwebkit
in qwebview
i have heard that we have to install an event filter and get the object which is at that position but i am not geting it
can you tell me a simple and sweet solution
tell how to set the operation of that action
also iut would be great if you can give a sample live working code
i have heard that we have to use QMenu and QAction for this.
To get a "standard" menu from QWebView based upon where you clicked, do:
page()->updatePositionDependentActions(pos);
QMenu* ctxMenu = page()->createStandardContextMenu();
to know on what you clicked, use
QWebHitTestResult hit = page()->mainFrame()->hitTestContent(pressPoint.toPoint());

Qt signals and slots working

I have created a Main Window which consists of menu bar with the first menu being "file". Now I am trying to open another window if I click on the "file" menu item. But I am not getting the receiver object of the other window while designing. How can I establish a link?
I am using Qt 4.7
I don't think you can do it by manual linking - this time you will have to write it yourself :P
Simply add a new slot to your window's class, add include for second's window header. Then in slot implementation create new window if necesary and simply call show on it.
Secondly you have to connect file meny to your signal - best is to add connect call in your window constructor AFTER intializing ui.
Also note that if your file option contains actually any submenu, then it's signal will never be emmited, so you need to think about something else in such case.

Application.application.nativeWindow.activate() problem on Windows

I have an AIR application with a system tray icon. When clicked it shows and activates the app. This is working as expected when the app is hidden (docked), however if I select another application so my app is in the background clicking on the system tray icon does nothing.
Oddly I also have a contextual menu on the system tray icon, which has an option to restore, this calls the same event handler as ScreenMouseEvent.CLICK, yet works.
I expect it's something to do with the contextual menu changing the focus, perhaps it's a bug in how AIR works with the system tray, perhaps it's just something I'm missing. Would be good to know if that's the case.
Thanks in advance
Rob
//instead of just calling
activate();
//call
nativeApplication.activate()
//or even better
nativeApplication.activate(nativeWindow);
Update based on OP's input: if you have multiple windows open for the application, use:
nativeApplication.activate(nativeApplication.openedWindows[0]);
If you are not in the main WindowedApplication class, you can use the static property NativeApplication.nativeApplication to get a reference to the singleton object.
WindowedApplication.activate()
Activates the underlying NativeWindow (even if this application is not the active one).
NativeApplication.activate(window:NativeWindow = null)
Activates this application. If the operating system allows activation, then the specified window is activated and brought to the desktop foreground; that is, in front of the windows of other applications. (If the window parameter is null, then a visible window of this application is activated.)
livedocs is not clear on why this is happening. It says activate() activates the underlying native window - one would expect it to be brought to the front when it is activated, but that's not happening.

Resources