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. Transparent window has different behavior between Linux platform and Windows platform?
QtWS25 Last Chance

Transparent window has different behavior between Linux platform and Windows platform?

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 4 Posters 563 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.
  • MozzieM Offline
    MozzieM Offline
    Mozzie
    wrote on last edited by
    #1

    Hi,

    I have an application which have a mainwindow and a dialog, I need part of the dialog become transparent so I can click the mainwindow through the transparent part. I test it on Windows, it works fine, but after running on Linux, the dialog can only see the mainwindow through the transparent part of the dialog, but I can not click the mainwindow through the transparent part. on Windows, I can trigger the click event through the transparent part.

    to implement the transparent , I write the following code in my dialog constructor:

    	setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
    	setAttribute(Qt::WA_TranslucentBackground, true);
    

    and in the .ui file , I have set stylesheet

    QWidget {background-color:transparent}
    

    I am using Qt5.12, Windows 10 and Ubuntu 18

    Thank you

    jsulmJ 1 Reply Last reply
    0
    • MozzieM Mozzie

      Hi,

      I have an application which have a mainwindow and a dialog, I need part of the dialog become transparent so I can click the mainwindow through the transparent part. I test it on Windows, it works fine, but after running on Linux, the dialog can only see the mainwindow through the transparent part of the dialog, but I can not click the mainwindow through the transparent part. on Windows, I can trigger the click event through the transparent part.

      to implement the transparent , I write the following code in my dialog constructor:

      	setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
      	setAttribute(Qt::WA_TranslucentBackground, true);
      

      and in the .ui file , I have set stylesheet

      QWidget {background-color:transparent}
      

      I am using Qt5.12, Windows 10 and Ubuntu 18

      Thank you

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Mozzie said in Transparent window has different behavior between Linux platform and Windows platform?:

      I can trigger the click event through the transparent part

      Please show how you're doing this. It should work same way on Linux.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      MozzieM 1 Reply Last reply
      0
      • jsulmJ jsulm

        @Mozzie said in Transparent window has different behavior between Linux platform and Windows platform?:

        I can trigger the click event through the transparent part

        Please show how you're doing this. It should work same way on Linux.

        MozzieM Offline
        MozzieM Offline
        Mozzie
        wrote on last edited by
        #3

        @jsulm

        Hi,
        such as I have a button on my mainwindow, and is the dialog is not transparent , the button will be cover up. but after make it transparent , on Windows I can click it by the left mouse button, on Linux, I can not.

        I override the mouse event of main window and dialog, on Windows, if I click the transparent part of the dialog, the even will get into QMainWindow::mouseXXXEvent, but on Linux if I click the transparent part of the dialog, the even will get into QDialog::mouseXXXEvent, if I change the dialog to a widge, the problem still.

        Thank you

        jsulmJ 1 Reply Last reply
        0
        • MozzieM Mozzie

          @jsulm

          Hi,
          such as I have a button on my mainwindow, and is the dialog is not transparent , the button will be cover up. but after make it transparent , on Windows I can click it by the left mouse button, on Linux, I can not.

          I override the mouse event of main window and dialog, on Windows, if I click the transparent part of the dialog, the even will get into QMainWindow::mouseXXXEvent, but on Linux if I click the transparent part of the dialog, the even will get into QDialog::mouseXXXEvent, if I change the dialog to a widge, the problem still.

          Thank you

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Mozzie said in Transparent window has different behavior between Linux platform and Windows platform?:

          but after make it transparent , on Windows I can click it by the left mouse button

          I'm surprised this works.
          Transparency actually means the the widget is visually transparent, not that it is "transparent" for the mouse.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          MozzieM 1 Reply Last reply
          0
          • jsulmJ jsulm

            @Mozzie said in Transparent window has different behavior between Linux platform and Windows platform?:

            but after make it transparent , on Windows I can click it by the left mouse button

            I'm surprised this works.
            Transparency actually means the the widget is visually transparent, not that it is "transparent" for the mouse.

            MozzieM Offline
            MozzieM Offline
            Mozzie
            wrote on last edited by
            #5

            @jsulm

            on Windows, this could work, I dont know why. so visually transparent should be the default behavior?
            is there any way to transfer event from transparent part not all the event of the dialog to the widget belong to the mainwindow.
            I only know installEventFilter and QApplication::posEvent but it seems its very complex to because I have to check the transparency of that point and find which widget is under that point.

            Thank you

            jsulmJ 1 Reply Last reply
            0
            • MozzieM Mozzie

              @jsulm

              on Windows, this could work, I dont know why. so visually transparent should be the default behavior?
              is there any way to transfer event from transparent part not all the event of the dialog to the widget belong to the mainwindow.
              I only know installEventFilter and QApplication::posEvent but it seems its very complex to because I have to check the transparency of that point and find which widget is under that point.

              Thank you

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Mozzie On Linux I think it depends a lot on what window manager is used.
              I guess to be on the safe side you will need to go for installEventFilter.
              Maybe somebody else knows more about this.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              MozzieM 1 Reply Last reply
              0
              • jsulmJ jsulm

                @Mozzie On Linux I think it depends a lot on what window manager is used.
                I guess to be on the safe side you will need to go for installEventFilter.
                Maybe somebody else knows more about this.

                MozzieM Offline
                MozzieM Offline
                Mozzie
                wrote on last edited by
                #7

                @jsulm

                Thank you very much.

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mpergand
                  wrote on last edited by mpergand
                  #8

                  Maybe tweaking with this widget attribute:

                  Qt::WA_TransparentForMouseEvents 51
                  When enabled, this attribute disables the delivery of mouse events to the widget and its children. Mouse events are delivered to other widgets as if the widget and its children were not present in the widget hierarchy; mouse clicks and other events effectively "pass through" them. This attribute is disabled by default.

                  MozzieM 1 Reply Last reply
                  1
                  • M mpergand

                    Maybe tweaking with this widget attribute:

                    Qt::WA_TransparentForMouseEvents 51
                    When enabled, this attribute disables the delivery of mouse events to the widget and its children. Mouse events are delivered to other widgets as if the widget and its children were not present in the widget hierarchy; mouse clicks and other events effectively "pass through" them. This attribute is disabled by default.

                    MozzieM Offline
                    MozzieM Offline
                    Mozzie
                    wrote on last edited by
                    #9

                    @mpergand

                    Thank you.

                    When enabled, this attribute disables the delivery of mouse events to the widget and its children.
                    

                    This might be not suitable, because there is some part of the dialog is not transparent still need receive the mouse event, but this attribute will "pass through" all of the child widgets?

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SimonSchroeder
                      wrote on last edited by
                      #10

                      Qt has a feature for this, i.e. masking of widgets. Have a look at their shaped clock example: https://doc.qt.io/qt-5/qtwidgets-widgets-shapedclock-example.html

                      1 Reply Last reply
                      1

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved