Results 1 to 1 of 1

Thread: QQuickWindow is not coming on top, if I make the visible false QQuickWindow as true

  1. #1
    Join Date
    May 2015
    Posts
    26
    Thanks
    11
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QQuickWindow is not coming on top, if I make the visible false QQuickWindow as true

    I have designed this below code like if the user launches the application for the first time , then the application will load Mainwindow.qml or basic.qml based on the flag "bSettingMainWindow" . Next time based on the switch button click from application will load another window (other than first one) and making the first launched qml window visible false. Once both of them launched once, then 2 windows will play with visibility true or false on click of switch button or signal is emitted.

    This below code is working perfectly fine except the window is not coming on top after making visible true. I have tried using raise() and activatewindow() even after that i am facing the same issue.

    Requesting to please provide any solution for to make the window come on top when i play with visibility. Currently this application window is settling behind some other application like for example outlook, after making visible true.

    Note: I have asked this question in my previous thread, But i didnt got any solution for this question(yes i have got solution for my other questions) so I am asking again with new thread since the previous thread has so many other contents which are not required. Click here to view

    Please find the code below

    Qt Code:
    1. //CustomWindow.h
    2. class CustomWindow : public QQuickWindow {
    3. //Custom QQuick window used in QML
    4. }
    5.  
    6.  
    7. //** windowLoader.hpp **//
    8. class WindowLoader : public QObject{
    9. Q_OBJECT
    10. QQmlApplicationEngine loadQMlEngine;
    11.  
    12. public:
    13. explicit WindowLoader(QObject * parent = 0);
    14. void loadWindow();
    15.  
    16.  
    17. public slots:
    18. void loadMainWindow();
    19. void loadBasicWindow();
    20. void connectToMain(QObject *object = nullptr, const QUrl &url = QUrl(""));
    21. void connectToBasic(QObject *object = nullptr, const QUrl &url = QUrl(""));
    22.  
    23. private:
    24. };
    25.  
    26.  
    27.  
    28. //** windowLoader.cpp **//
    29. WindowLoader::WindowLoader(QObject *parent) : QObject(parent) {
    30.  
    31. }
    32.  
    33. //This function will be called only one time during launch
    34. void WindowLoader::loadWindow() {
    35. if(bSettingMainWindow){ //this will be from a internal flag, this check is only one time during launch
    36. connect(&loadQMlEngine,SIGNAL(objectCreated(QObject *, const QUrl &)),this,SLOT(connectToBasic(QObject *, const QUrl &)),Qt::QueuedConnection);
    37. loadQMlEngine.rootContext()->setContextProperty( "interface", m_interface );
    38. loadQMlEngine.load(QUrl(QStringLiteral("qrc:/Qml/mainWindow.qml")));
    39. m_iMainWindowIndex = 0;
    40. m_iBasicWindowIndex = 1;
    41. } else {
    42. connect(&loadQMlEngine,SIGNAL(objectCreated(QObject *, const QUrl &)),this,SLOT(connectToMain(QObject *, const QUrl &)),Qt::QueuedConnection);
    43. loadQMlEngine.rootContext()->setContextProperty( "interface", m_interface );
    44. loadQMlEngine.load(QUrl(QStringLiteral("qrc:/Qml/basic.qml")));
    45. m_iMainWindowIndex = 1;
    46. m_iBasicWindowIndex = 0;
    47. }
    48. }
    49.  
    50. void WindowLoader::connectToBasic(QObject *object, const QUrl &url) {
    51. if(object){
    52. connect(object, SIGNAL(switchToBasicSignal()), this, SLOT(loadBasicWindow()));
    53. }
    54. }
    55.  
    56. void WindowLoader::connectToMain(QObject *object, const QUrl &url) {
    57. if(object){
    58. connect(object, SIGNAL(switchToMainSignal()), this, SLOT(loadMainWindow()));
    59. }
    60. }
    61.  
    62. void WindowLoader::loadBasicWindow() {
    63.  
    64. if(loadQMlEngine.rootObjects().size() <= 2) {
    65. disconnect(&loadQMlEngine,SIGNAL(objectCreated(QObject *, const QUrl &)),this,SLOT(connectToBasic(QObject *, const QUrl &)));
    66. }
    67.  
    68. if(loadQMlEngine.rootObjects().size() < 2) {
    69. loadQMlEngine.rootObjects()[m_iMainWindowIndex]->setProperty("visible",false);
    70. connect(&loadQMlEngine,SIGNAL(objectCreated(QObject *, const QUrl &)),this,SLOT(connectToMain(QObject *, const QUrl &)),Qt::QueuedConnection);
    71. loadQMlEngine.rootContext()->setContextProperty( "interface", m_interface );
    72. loadQMlEngine.load(QUrl(QStringLiteral("qrc:/Qml/basic.qml")));
    73. } else {
    74. //QMetaObject::invokeMethod(loadQMlEngine.rootObjects()[m_iBasicWindowIndex],"show");
    75. //QMetaObject::invokeMethod(loadQMlEngine.rootObjects()[m_iMainWindowIndex],"hide");
    76. loadQMlEngine.rootObjects()[m_iBasicWindowIndex]->setProperty("visible",true);
    77. loadQMlEngine.rootObjects()[m_iMainWindowIndex]->setProperty("visible",false);
    78. }
    79. }
    80.  
    81. void WindowLoader::loadMainWindow() {
    82.  
    83. if(loadQMlEngine.rootObjects().size() <= 2) {
    84. disconnect(&loadQMlEngine,SIGNAL(objectCreated(QObject *, const QUrl &)),this,SLOT(connectToMain(QObject *, const QUrl &)));
    85. }
    86.  
    87. if(loadQMlEngine.rootObjects().size() < 2) {
    88. loadQMlEngine.rootObjects()[m_iBasicWindowIndex]->setProperty("visible",false);
    89. connect(&loadQMlEngine,SIGNAL(objectCreated(QObject *, const QUrl &)),this,SLOT(connectToBasic(QObject *, const QUrl &)),Qt::QueuedConnection);
    90. loadQMlEngine.rootContext()->setContextProperty( "interface", m_interface );
    91. loadQMlEngine.load(QUrl(QStringLiteral("qrc:/Qml/mainWindow.qml")));
    92. } else {
    93. //QMetaObject::invokeMethod(loadQMlEngine.rootObjects()[m_iBasicWindowIndex],"hide");
    94. //QMetaObject::invokeMethod(loadQMlEngine.rootObjects()[m_iMainWindowIndex],"show");
    95. loadQMlEngine.rootObjects()[m_iBasicWindowIndex]->setProperty("visible",false);
    96. loadQMlEngine.rootObjects()[m_iMainWindowIndex]->setProperty("visible",true);
    97. }
    98. }
    99.  
    100.  
    101. //** main.cpp **//
    102. int main( int argc, char *argv[] ) {
    103. QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    104. QApplication app(argc, argv);
    105. qmlRegisterType<CustomWindow>("CNQml", 1, 0, "CustomWindow");
    106. WindowLoader root;
    107. root.loadWindow();
    108. return app.exec();
    109. }
    110.  
    111. //*********** QML Code ************
    112. // ** mainWindow.qml **//
    113. CustomWindow {
    114. visible: true
    115. width: 1200
    116. height: 800
    117. title: qsTr("MainWindow")
    118.  
    119. signal switchToBasicSignal()
    120.  
    121. Rectangle {
    122. anchors.fill: parent
    123. MouseArea{
    124. anchors.fill: parent
    125. onClicked: {
    126. switchToBasicSignal()
    127. }
    128. }
    129. }
    130. }
    131.  
    132. //** basic.qml **//
    133. CustomWindow {
    134. visible: true
    135. width: 640
    136. height: 480
    137. title: qsTr("basicwindow")
    138.  
    139. signal switchToMainSignal()
    140.  
    141. Rectangle {
    142. anchors.fill: parent
    143. MouseArea{
    144. anchors.fill: parent
    145. onClicked: {
    146. switchToMainSignal()
    147. }
    148. }
    149. }
    150. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by gowreesh; 7th July 2020 at 14:22.

Similar Threads

  1. Make True or False a variable
    By dennisvz in forum Newbie
    Replies: 3
    Last Post: 26th April 2019, 23:56
  2. Passing synthetic keyboard events to the QQuickWindow
    By velorums in forum Qt Programming
    Replies: 2
    Last Post: 5th January 2016, 07:35
  3. QQuickWindow::grabWindow: scene graph already in use
    By TheIndependentAquarius in forum Qt Quick
    Replies: 5
    Last Post: 17th October 2015, 12:27
  4. Ugly QQuickWindow
    By Brandybuck in forum Qt Quick
    Replies: 0
    Last Post: 5th February 2013, 02:05
  5. how to make menu visible false?
    By rajesh in forum Qt Programming
    Replies: 2
    Last Post: 18th July 2006, 11:04

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.