Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Weird behaviour with Qml (transparent background)
Qt 6.11 is out! See what's new in the release blog

Weird behaviour with Qml (transparent background)

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 434 Views 2 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.
  • U Offline
    U Offline
    uncore
    wrote last edited by
    #1

    I am trying to achieve a transparent background in Qml for Win11 mica effect but for some reason the app starts with a white background and as i resize the window it becomes transparent what am i doing wrong ?

    Qml :

    import QtQuick 2.12
    import QtQuick.Controls 2.12
    import QtQuick.Controls.Universal 2.12
    
    import QtQml 2.12
    
    ApplicationWindow {
        visible: true
        color: "transparent"
        width: 640
        height: 480
    
        Button {
            id: btn
            text: "Button"
            anchors.centerIn: parent
        }
    }
    

    Win11 , Qt 6.8.3 , also happens on Qt6.9.3

    You can clone to reproduce,
    https://github.com/uncor3/qml-bug

    bug.gif

    1 Reply Last reply
    0
    • KH-219DesignK Offline
      KH-219DesignK Offline
      KH-219Design
      wrote last edited by KH-219Design
      #2

      (At least in Qt 5, I think the following was needed. Not sure in Qt6)

      Does it help if you try this flags setting?

      ApplicationWindow {
      
      
        flags: Qt.WA_TranslucentBackground // or perhaps not. (see correction below)
        color: "transparent"
      
      

      UPDATE: whatever I was remembering or mis-rembering from Qt5 days, @jeremy_k has pointed out that I must be mistaken (and I concur).

      (I didn't want to merely delete this comment, because when I come across "this post deleted" I always assume there was some weird spam initially, and that is not what this was!)

      www.219design.com
      Software | Electrical | Mechanical | Product Design

      jeremy_kJ 1 Reply Last reply
      1
      • KH-219DesignK KH-219Design

        (At least in Qt 5, I think the following was needed. Not sure in Qt6)

        Does it help if you try this flags setting?

        ApplicationWindow {
        
        
          flags: Qt.WA_TranslucentBackground // or perhaps not. (see correction below)
          color: "transparent"
        
        

        UPDATE: whatever I was remembering or mis-rembering from Qt5 days, @jeremy_k has pointed out that I must be mistaken (and I concur).

        (I didn't want to merely delete this comment, because when I come across "this post deleted" I always assume there was some weird spam initially, and that is not what this was!)

        jeremy_kJ Offline
        jeremy_kJ Offline
        jeremy_k
        wrote last edited by
        #3

        @KH-219Design said in Weird behaviour with Qml (transparent background):

        ApplicationWindow {
        
        
          flags: Qt.WA_TranslucentBackground
          color: "transparent"
        
        

        "WA" is short for WidgetAttribute, while Window.flags is expecting a combination of WindowFlags.

        Asking a question about code? http://eel.is/iso-c++/testcase/

        1 Reply Last reply
        1
        • J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote last edited by
          #4

          Try the following:

          ApplicationWindow {
              id: rootWindowd
              visible: false
              color: "transparent"
              width: 640
              height: 480
          
              Component.onCompleted: rootWindowd.visible = true
          
              Button {
                  id: btn
                  text: "Button"
                  anchors.centerIn: parent
              }
          }
          

          that should force a redraw after everything is finished/initialized

          or

          function forceRedraw() {
                  rootWindowd.contentItem.update()
              }
          

          If this works, than I would consider it a bug in the framework and you should open a bug report


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          0
          • U Offline
            U Offline
            uncore
            wrote last edited by
            #5

            @J.Hilk Didn't work. I actually tried forcing a rerender from both C++ and Qml side before but didn't work. Also this doesn't have anything to do with the Mica effect even i disable it the behavior is the same, starts with a white background then as i resize, it becomes transparent. Just tried with Qt 6.11.0 same result

            J.HilkJ 1 Reply Last reply
            0
            • U uncore

              @J.Hilk Didn't work. I actually tried forcing a rerender from both C++ and Qml side before but didn't work. Also this doesn't have anything to do with the Mica effect even i disable it the behavior is the same, starts with a white background then as i resize, it becomes transparent. Just tried with Qt 6.11.0 same result

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote last edited by J.Hilk
              #6

              @uncore the actual problem is a false assumption. The black you see is not the transparent background after resize. It's just not rendered.

              I don't know if you can actually get a normal ApplicationWindow with only a transparent background.

              The Only way I know is via the QtFramelessWindowHint:

              20d60691-52f3-4b4a-b1ed-591465ed7d0d-image.png

              but that comes with missing menu bar and stuff


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              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