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. How to resize the Qt Quick Test application window
QtWS25 Last Chance

How to resize the Qt Quick Test application window

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 1 Posters 379 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.
  • O Offline
    O Offline
    Oliver Starke CEOS
    wrote on last edited by Oliver Starke CEOS
    #1

    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

    1 Reply Last reply
    0
    • O Offline
      O Offline
      Oliver Starke CEOS
      wrote on last edited by
      #2

      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();
              }
        }
      };
      
      1 Reply Last reply
      0
      • O Offline
        O Offline
        Oliver Starke CEOS
        wrote on last edited by
        #3

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

        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