Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QQuickWidget with QML inside. Show another QML above but not in another window

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

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 Posters 623 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Diego DonateD Offline
    Diego DonateD Offline
    Diego Donate
    wrote on last edited by
    #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 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"
    }
    
    1 Reply Last reply
    0
    • Diego DonateD Offline
      Diego DonateD Offline
      Diego Donate
      wrote on last edited by
      #2

      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)

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved