我有一个带有QML的QQuickWidget(MovableWidget)(QML1:Test.qml)
这个QML有一个按钮,当点击时我想在QML2上面显示/隐藏另一个QML(Test2.qml),但不能在另一个窗口中显示(在Windows中,两个面板必须在同一个“任务栏”窗口中) 。 QML1必须保持两种情况下的位置,QML1可见或隐藏
我试图在QML1中添加一个QML2实例,将其设置在上面,但我无法在QML1边界外绘制。所以我想我必须增加QML1的大小,以及TestWidget的大小,但在这种情况下,我所取得的最好的事情是窗口增加但是到底...
的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"
}