Some questions about put QWidget in QML



  • I need to put my custom widget which inherit from QWidget into QML as a component, I did this jobs to make it :

    1. define a class named WidgetComp inherit from QQuickItem(or QObject).
    2. define a class named MyWidget to make my custom widget.
    3. declare a MyWidget member varible in class WidgetComp.
    4. use Q_INVOKABLE to declare a funtion named showWidget() in class WidgetComp. then I can use it to show my custom widget in QML
    5. register WidgetComp as a QML Componet

    just like this:
    0_1553842261034_WidgetComp.png

    Now I'm succeed to make it as a component, I can ues it in QML correctly, and it does shown.
    But there are some problems exist:

    1. In main.qml: I put WidgetComp in Window, but Window seems not the parent of WidgetComp, because when I set coordinate of WidgetComp , for example: (0, 0). MyWidget shows at the Origin of whole screen, but not the Origin of the Window.
    2. when I use Android GCC to compile it, setting the coordinate and size(height and width) cames unuseful, it fills full screen at all time whatever how I set those property.

    Is there anybody has the experience about this, help me plz, I would be really appreciated!


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You can take a look at KDAB's DeclarativeWidgets project. It's library to use QWidgets in QML application.



  • This post is deleted!


  • @SGaist said in Some questions about put QWidget in QML:

    Hi and welcome to devnet,

    You can take a look at KDAB's DeclarativeWidgets project. It's library to use QWidgets in QML application.

    thanks very much and I will have a good look


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.