Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to resize the Qt Quick Test application window



  • Starting my qml test application the test app is shown in a small window (about 100px x100px) by default. I did not find a way to resize it (I would like to have a mximzed window ) since I do not have access to the application window ( or dont know how..) Any ideas ?
    PS: I use the QUICK_TEST_MAIN_WITH_SETUP macro to setup some c++ components to be used by the QML TestCases.
    ANd I use Qt 5.12 for Windows.

    in qmlscene I can resize the window to the size of the root item. Does anyone know if/how this is possible within Qt Quick Test framework ?

    I searched for a solution the whole afternoon, but without success. Every hint is appreciated !!!
    Thanks in advance...
    BR
    Oliver



  • I am now able to resize the window. I implemented my own utility functions which are invokable on qml side (They must be called from qml because the topLevelWindows of QGUiApplication are only available after the window has been created and shown) This is done by the test framework for each test case execution. I attached the corresponding code, if someone has the same requirements while writing gui tests using QMl TestCase. For me this is a basic test utlity function that should be provided by the framework. Perhaps I will create a feature request for this...

    class GuiTestUtils : public QObject
    {
        Q_OBJECT
    public:
        // Utility function to be able to delete files from within a QML test case.
        Q_INVOKABLE void deleteFile(const QString& fileName) { QFile::remove(fileName); }
        Q_INVOKABLE void copyFile(const QString& sourceFileName, const QString& destinationFileName)
        {
            if(!QFile::copy(sourceFileName, destinationFileName))
            {
                qCritical() << "failed to copy " << sourceFileName << " to " << destinationFileName;
            }
        }
    
        QWindow* getTestCaseWindow()
        {
            QWindowList topLevelWindows = qApp->topLevelWindows();
            QWindow* curTestCaseWindow = nullptr;
    
            qDebug() << "application name: " << qApp->applicationDisplayName();
            qDebug() << "count of TopLevel - windows: " << topLevelWindows.size();
    
            // Todo: find a way to retreive the Filename of the currently loaded qml root item
            // because the name of the file is the title of the window.
            for(int i = 0; i < topLevelWindows.size(); ++i)
            {
                if(topLevelWindows[i]->title() != "Simulation Output Log")
                {
                    curTestCaseWindow = topLevelWindows[i];
                    qDebug() << "found test case top level window : " << curTestCaseWindow->title();
                }
                else
                {
                    qDebug() << "available top level window [" << i << "] : " << topLevelWindows[i]->title();
                }
            }
    
            return curTestCaseWindow;
        }
    
        Q_INVOKABLE void maximizeWindow()
        {
            QWindow* curTestCaseWindow = getTestCaseWindow();
            if(curTestCaseWindow != nullptr)
            {
                curTestCaseWindow->showMaximized();
            }
        }
    
        Q_INVOKABLE void minimizeWindow()
        {
            QWindow* curTestCaseWindow = getTestCaseWindow();
            if(curTestCaseWindow != nullptr)
            {
                curTestCaseWindow->showMinimized();
            }
      }
    };
    


  • I forgot to mention that a instance of GuiTestUtils is made available to QML using setContextProperty...


Log in to reply