1
  MouseArea {
                anchors.fill: parent
                hoverEnabled: true
                         acceptedButtons: Qt.LeftButton | Qt.RightButton
                         onEntered: Function.call(somefunc())
                         onExited: console.log("Mouse Exited");
                onClicked: {
                    Qt.quit();
                }
            }

How to create a new window using the function somefunc() when my mouse enters the Mouse Area. Is it possible?
I cannot find any way to integrate a C++ file into Qt so that I can use the function to create a new window.

Jino
  • 345
  • 1
  • 2
  • 16

2 Answers2

2

Yes, it is possible to achieve what you want. C++ and QML can work together in some ways but none of them (as far as I know) involves embedding the C++ code into the QML code. Before going forward I recommend you to ask yourself the following:

  1. Why not defining the window itself in QML?
  2. Why not defining somefunc() in JavaScript, a language you can use in your QML file.
mhcuervo
  • 2,610
  • 22
  • 33
1

It's possible create a new window even from Qml or C++, but in Qml is most easy, you can declare Component element containing a element of qml (how show a pop up but the functionality how window is very limited) or create a Window element, read this:

How can I create a new window from within QML?

And this: http://qt-project.org/doc/qt-4.8/qdeclarativedynamicobjects.html, maybe this can help.

Community
  • 1
  • 1
APRocha
  • 280
  • 6
  • 24