Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using QGeoView in ui.qml #24

Open
Tevhit opened this issue Feb 11, 2022 · 9 comments
Open

Using QGeoView in ui.qml #24

Tevhit opened this issue Feb 11, 2022 · 9 comments

Comments

@Tevhit
Copy link

Tevhit commented Feb 11, 2022

How can I use QGeoView widget in a sample ui.qml file?

@embeddedmz
Copy link

This project was created to offer an alternative to Qt maps that are only available in QML. So use Qt maps (QLocation ) if you need to add a map to your QML program.

@Tevhit
Copy link
Author

Tevhit commented Feb 11, 2022

Qt Location and Qt Positioning are removed modules for QT6. So, how can I use QLocation in my QML program?

@embeddedmz
Copy link

Are you sure ?

@Tevhit
Copy link
Author

Tevhit commented Feb 11, 2022

https://doc-snapshots.qt.io/qt6-dev/whatsnew60.html

@Tevhit
Copy link
Author

Tevhit commented Feb 11, 2022

Is it correct?

@AmonRaNet
Copy link
Owner

QGeoView is QtWidget solution and not well adopted to be used in QML.
In any case in theory it is possible (but I have not tried yet, therefore in theory). QGeoView based on QGraphicsView, which has method render (https://doc.qt.io/qt-5/qgraphicsview.html#render) and as result you can render view to any painter, including QML ones.
You can create custom QQuickPaintedItem and override paint method to render QGeoView directly to painter (instance of QGeoView will be no rendered by itself). It can be still fast enough if OpenGL is enabled (https://doc.qt.io/qt-5/qquickpainteditem.html). But this is only about render - it mean you will need to propagate all events from QML (resize, mouse, keyboard) to QGeoView. Also all QGeoView widgets (compas, scale, zoom buttons) will not work and you will need to create QML based alternative. At the end you will have QGeoView rendered as "image" in QML scene with control by QML events. If you will give a try - please inform us about results 😉

P.S. here is related topic: https://forum.qt.io/topic/74727/rendering-qgraphicsscene-into-qml-scene-texture

@embeddedmz
Copy link

Stick to Qt 5 if you can.

Regards.

@Tevhit
Copy link
Author

Tevhit commented Feb 22, 2022

Hello @AmonRaNet,
We tried as that; we created a class, it has inheritance from QQuickPaintedItem Class. We overrided paint() method for rendering. Initial the QGeoView map rendered and painted. It can shown in QML as an image. So, it is not possible touching on the map. It was an image on screen.
Do you have an idea for touching on the map in QML, of course we have to keep in mind it is an image in QML. Thanks all.

@AmonRaNet
Copy link
Owner

AmonRaNet commented Feb 22, 2022

@Tevhit You need to forward mouse/touch events from QML to QGeoView.

Lets say you will create some proxy QObject class and will add it instance as property to QQuickPaintedItem, than you can access it over QML. Very simplified (you need to send all events press, release, etc):

in cpp:

class Proxy: public QObject
{
Q_OBJECT
public:
Proxy(QGeoView* view) : m_view{view} {}

public slots:
void mousePress(x,y,...) {
  QMouseEvent *event = new QMouseEvent(QEvent::MouseButtonPress, QPoint{x,y}, Qt::LeftButton, Qt::NoButton,  Qt::NoModifier);
  QCoreApplication::postEvent(m_view, event);
}
// other events...
}

class MyQQuickPaintedItem: public QQuickPaintedItem
{
Q_OBJECT
Q_PROPERTY(Proxy* myProxy MEMBER myProxy CONSTANT)
}

in QML:

MyQQuickPaintedItem {
    id: painter
    width: 100; height: 100

    MouseArea {
        anchors.fill: parent
        onPressed: { 
            painter.myProxy.mousePress(mouse.x, mouse.y,...);
            painter.update();
       }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants