Results 1 to 4 of 4

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

  1. #1
    Join Date
    Apr 2013
    Posts
    61
    Qt products
    Qt4
    Platforms
    Windows

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

    0
    down vote
    favorite
    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

    .
    Qt Code:
    1. ..
    2. MovableWidget *view = new MovableWidget;
    3. view->setSource(QUrl("qrc:/Test.qml"));
    4. view->setWindowFlags(Qt::FramelessWindowHint);
    5. view->show();
    6. if (view->rootObject())
    7. QObject::connect(view->rootObject(), SIGNAL(signal_showMenu(bool)), view, SLOT(onMenuShown(bool)));
    8. ...
    To copy to clipboard, switch view to plain text mode 

    MovableWidget.cpp
    Qt Code:
    1. #include "movableWidget.h"
    2.  
    3. #include <QMouseEvent>
    4.  
    5. // ****************************************************************************
    6. MovableWidget::MovableWidget(QWidget *parent)
    7. : QQuickWidget(parent)
    8. {
    9. }
    10.  
    11. // ****************************************************************************
    12. void SptMiniWindow::onMenuShown(bool bShown)
    13. {
    14. // setGeometry() here? parameters??
    15. }
    To copy to clipboard, switch view to plain text mode 

    Test1.qml

    Qt Code:
    1. import QtQuick 2.0
    2.  
    3. Rectangle {
    4. id: myWindow
    5.  
    6. signal signal_showMenu(bool show)
    7.  
    8. width: 250; height: 100
    9. color: "red"
    10.  
    11. Button {
    12. id: idButtonClick
    13.  
    14. anchors { bottom: parent.bottom; bottomMargin: 10; horizontalCenter: parent.horizontalCenter }
    15.  
    16. height: 20
    17. width: 50
    18.  
    19. text: "click"
    20.  
    21. onClicked: {
    22. console.log("idButtonClick");
    23. test2.visible = !test2.visible
    24.  
    25. // Here 'myWindow' height must be changed?
    26.  
    27. signal_showMenu(test2.visible)
    28. }
    29.  
    30. Test2 {
    31. id: test2
    32. anchors { bottom: myWindow.top; left: myWindow.left; right: myWindow.right; }
    33. height: 50
    34. visible: false
    35. }
    36. }
    To copy to clipboard, switch view to plain text mode 
    Test2.qml
    Qt Code:
    1. import QtQuick 2.0
    2.  
    3. Rectangle {
    4. color: "green"
    5. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

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

    What do you need to call into C++ for?
    Do you want to load a different QML file into the view? I.e. do you want to replace the window's content?

    Cheers,
    _

  3. #3
    Join Date
    Apr 2013
    Posts
    61
    Qt products
    Qt4
    Platforms
    Windows

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

    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)
    Thanks!

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

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

    Ok, so another window.

    Instead of the script based approach to dynamic loading you might also want to look at the Loader element.

    Cheers,
    _

Similar Threads

  1. Replies: 7
    Last Post: 25th July 2016, 15:42
  2. Replies: 1
    Last Post: 12th March 2013, 12:49
  3. Replies: 3
    Last Post: 20th October 2010, 23:36
  4. Replies: 3
    Last Post: 17th March 2010, 17:47
  5. Open a window inside another window
    By passerb in forum Qt Programming
    Replies: 6
    Last Post: 18th October 2009, 14:24

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.