Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Qt5 -> Qt6 - partial window transparency
Qt 6.12 LTS is out! See what's new in the release blog

Qt5 -> Qt6 - partial window transparency

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 2 Posters 1.5k Views 1 Watching
  • 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.
  • A Offline
    A Offline
    aran
    wrote on last edited by aran
    #1

    Hi all,

    I'm trying to port an application from Qt5 to Qt6, but I'm having some trouble getting (partial) window transparency to work in Windows (it works just fine in Linux).

    To test this, I simply created a new project in QtCreator for Qt5 (5.15) and Qt6 (6.2), so it's a simple Window with a "Hello World" title. I then add color: #88000000 to both Window elements, build it and run it. The Qt5 version looks as expected, the window is black and partially transparent. The Qt6 version, however, does not have any transparency at all.

    If I do the same, however, on Linux, then both look exactly the same.

    Did anybody run into this before, or does anybody have an idea what to look into?

    Thanks!

    A 1 Reply Last reply
    1
    • A aran

      Hi all,

      I'm trying to port an application from Qt5 to Qt6, but I'm having some trouble getting (partial) window transparency to work in Windows (it works just fine in Linux).

      To test this, I simply created a new project in QtCreator for Qt5 (5.15) and Qt6 (6.2), so it's a simple Window with a "Hello World" title. I then add color: #88000000 to both Window elements, build it and run it. The Qt5 version looks as expected, the window is black and partially transparent. The Qt6 version, however, does not have any transparency at all.

      If I do the same, however, on Linux, then both look exactly the same.

      Did anybody run into this before, or does anybody have an idea what to look into?

      Thanks!

      A Offline
      A Offline
      Asperamanca
      wrote on last edited by
      #2

      @aran
      How do you create a Window?

      When using QQuickView, I can make it work with the following code:

              // See https://stackoverflow.com/questions/14009549/how-to-make-a-transparent-window-with-qt-quick-2-0
              QSurfaceFormat surfaceFormat;
              surfaceFormat.setAlphaBufferSize(8);
              pQuickView->setFormat(surfaceFormat);
              pQuickView->setColor(QColor(Qt::transparent));
      

      (a semi-transparent color should work then, as well)

      1 Reply Last reply
      0
      • A Offline
        A Offline
        aran
        wrote on last edited by
        #3

        Thank you for your reply!

        I've been using QQmlApplicationEngine to load and display the window. If I switch it to QQuickView I also don't get a transparent window.

        Here is the example code I'm running:

        main.cpp:

        #include <QGuiApplication>
        #include <QQmlApplicationEngine>
        #include <QQuickView>
        
        int main(int argc, char *argv[])
        {
            QGuiApplication app(argc, argv);
        
            // creating application using engine
            // when uncommenting this also make sure to replace
            // Rectangle by Window in Main.qml
        /*    QQmlApplicationEngine engine;
            const QUrl url(u"qrc:/transparenttest/Main.qml"_qs);
            QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                &app, [url](QObject *obj, const QUrl &objUrl) {
                    if (!obj && url == objUrl)
                        QCoreApplication::exit(-1);
                }, Qt::QueuedConnection);
        
            engine.load(url);*/
        
            // creating the application using view
            QQuickView *view = new QQuickView;
            view->setSource(QUrl("qrc:/transparenttest/Main.qml"));
        
            QSurfaceFormat surfaceFormat;
            surfaceFormat.setAlphaBufferSize(8);
            view->setFormat(surfaceFormat);
            view->setColor(QColor(qRgba(0,0,0,128)));
            view->show();
        
            return app.exec();
        }
        

        (the commented out code is the default code provided by qt creator and (afaict) the recommended way (?) of creating qml applications.)

        Main.qml:

        import QtQuick
        import QtQuick.Controls
        import QtQuick.Window
        
        // use Window when running it with QQmlApplicationEngine
        //Window {
        Rectangle {
            width: 640
            height: 480
            visible: true
            color: "#88000000"
        }
        
        

        It also has some strange behavior when resizing the window, in particular when making it larger. The newly added areas are indeed semi-transparent. It seems like there is a central item or rectangle in the background that is all white at startup and stays around but doesn't resize...

        A 1 Reply Last reply
        0
        • A aran

          Thank you for your reply!

          I've been using QQmlApplicationEngine to load and display the window. If I switch it to QQuickView I also don't get a transparent window.

          Here is the example code I'm running:

          main.cpp:

          #include <QGuiApplication>
          #include <QQmlApplicationEngine>
          #include <QQuickView>
          
          int main(int argc, char *argv[])
          {
              QGuiApplication app(argc, argv);
          
              // creating application using engine
              // when uncommenting this also make sure to replace
              // Rectangle by Window in Main.qml
          /*    QQmlApplicationEngine engine;
              const QUrl url(u"qrc:/transparenttest/Main.qml"_qs);
              QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                  &app, [url](QObject *obj, const QUrl &objUrl) {
                      if (!obj && url == objUrl)
                          QCoreApplication::exit(-1);
                  }, Qt::QueuedConnection);
          
              engine.load(url);*/
          
              // creating the application using view
              QQuickView *view = new QQuickView;
              view->setSource(QUrl("qrc:/transparenttest/Main.qml"));
          
              QSurfaceFormat surfaceFormat;
              surfaceFormat.setAlphaBufferSize(8);
              view->setFormat(surfaceFormat);
              view->setColor(QColor(qRgba(0,0,0,128)));
              view->show();
          
              return app.exec();
          }
          

          (the commented out code is the default code provided by qt creator and (afaict) the recommended way (?) of creating qml applications.)

          Main.qml:

          import QtQuick
          import QtQuick.Controls
          import QtQuick.Window
          
          // use Window when running it with QQmlApplicationEngine
          //Window {
          Rectangle {
              width: 640
              height: 480
              visible: true
              color: "#88000000"
          }
          
          

          It also has some strange behavior when resizing the window, in particular when making it larger. The newly added areas are indeed semi-transparent. It seems like there is a central item or rectangle in the background that is all white at startup and stays around but doesn't resize...

          A Offline
          A Offline
          Asperamanca
          wrote on last edited by
          #4

          @aran I would try setting view color and surface format before loading source
          Also, you might want to try different RHI backends, and see how they behave.

          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
          • Unsolved