QQuickWidget with QML inside. Show another QML above but not in another window



  • I have a QQuickWidget (MovableWidget) with a QML inside (QML1: Test.qml)

    This QML has a button, and when clicked I want to show/hide another QML (Test2.qml) above QML2, but not in another window (in Windows, both panels must be in the same 'Task bar' window). QML1 must keep the position in both cases, with QML1 visible or hidden

    I tried to add a QML2 instance inside QML1, setting it above, but I can not paint outside QML1 boundaries. So I suppose I must increase QML1 size, and so TestWidget size, but in this case the best thing I have achieved is that the window is increased but to the bottom...

    main.cpp

    ...
    MovableWidget *view = new MovableWidget;
    view->setSource(QUrl("qrc:/Test.qml"));
    view->setWindowFlags(Qt::FramelessWindowHint);
    view->show();
    if (view->rootObject())
        QObject::connect(view->rootObject(), SIGNAL(signal_showMenu(bool)), view, SLOT(onMenuShown(bool)));
    ...
    

    MovableWidget.cpp

    #include "movableWidget.h"
    
    #include <QMouseEvent>
    
    // ****************************************************************************
    MovableWidget::MovableWidget(QWidget *parent)
        : QQuickWidget(parent)
    {
    }
    
    // ****************************************************************************
    void SptMiniWindow::onMenuShown(bool bShown)
    {
       // setGeometry() here? parameters??
    }
    

    Test1.qml

    import QtQuick 2.0
    
    Rectangle {
        id: myWindow
    
        signal signal_showMenu(bool show)
    
        width: 250; height: 100
        color: "red"
    
       Button {
            id: idButtonClick
    
            anchors { bottom: parent.bottom; bottomMargin: 10; horizontalCenter: parent.horizontalCenter }
    
            height: 20
            width: 50
    
            text: "click"
    
            onClicked: {
                console.log("idButtonClick");
                test2.visible = !test2.visible
    
                // Here 'myWindow' height must be changed?
    
                signal_showMenu(test2.visible)
         }
    
        Test2 {
            id: test2
            anchors { bottom: myWindow.top; left: myWindow.left; right: myWindow.right; }
            height: 50
            visible: false
        }
    }
    

    Test2.qml

    import QtQuick 2.0
    
    Rectangle {
        color: "green"
    }
    


  • What I wanted is to display a QML object above another QML object. Finally I have used a QML 'Window' object to set my QML object 2 above my QML object 1. I load the QML2 object dinamically (Qt.createComponent) in my QML1 I added "flags: Qt.Tool | Qt.FramelessWindowHint" to remove frame and avoid a new Windows window (what I needed)


Log in to reply
 

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