1

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 MovableWidget::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"
}
Diego
  • 336
  • 2
  • 21
  • What do you want to archive with all this code? What is `MovableWidget` and `SptMiniWindow` classes? What do you mean saying QML - an item? a QML file? What was an error or unexpected behavior? You should to clarify your question and provide [mcve](http://stackoverflow.com/help/mcve) if you expect to get an answer. – folibis Nov 22 '16 at 20:02
  • 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) – Diego Nov 24 '16 at 10:50
  • qml files are not html pages. They are class definitions. Stop trying to use them like pages. – Velkan Nov 29 '16 at 11:54

0 Answers0