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 on both mac and windows?

transparent window on both mac and windows?

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 2.1k 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.
  • D Offline
    D Offline
    davecotter
    wrote on 6 Nov 2020, 03:24 last edited by davecotter 11 Jun 2020, 17:08
    #1

    i have a minimal project link click HERE, based on "windowflags" example

    on mac, i can only get the desired effect if i do these steps:

    • check "translucent background" (ON)
    • check "no system background" (ON)
    • un-check "translucent background" (OFF)

    now i'm in the state where it looks like this:
    Screen Shot 2020-11-05 at 7.21.28 PM.png

    that's great, that's exactly what i want. but when i go to resize it, the transparent area fills with junk.

    On Windows, i can't get ANYTHING to cause the window to be transparent. I tried checking "frameless window" and "translucent background", as many people suggest, but that doesn't work. plus i need a widow i can drag around.

    anyone have any experience with this?

    i don't mind platform specific code if necessary, this is just mac and windows.

    J 1 Reply Last reply 6 Nov 2020, 06:01
    1
    • D davecotter
      6 Nov 2020, 03:24

      i have a minimal project link click HERE, based on "windowflags" example

      on mac, i can only get the desired effect if i do these steps:

      • check "translucent background" (ON)
      • check "no system background" (ON)
      • un-check "translucent background" (OFF)

      now i'm in the state where it looks like this:
      Screen Shot 2020-11-05 at 7.21.28 PM.png

      that's great, that's exactly what i want. but when i go to resize it, the transparent area fills with junk.

      On Windows, i can't get ANYTHING to cause the window to be transparent. I tried checking "frameless window" and "translucent background", as many people suggest, but that doesn't work. plus i need a widow i can drag around.

      anyone have any experience with this?

      i don't mind platform specific code if necessary, this is just mac and windows.

      J Online
      J Online
      J.Hilk
      Moderators
      wrote on 6 Nov 2020, 06:01 last edited by
      #2

      Hi @davecotter

      I have an app/standalone process that I launch as a splash screen, that has transparent background but it is not resizable.

      For the QWidget version I set the following flags & attributes:

      this->setWindowFlags( Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::WindowTransparentForInput);
      this->setAttribute(Qt::WA_TranslucentBackground,true);
      

      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
      • D Offline
        D Offline
        davecotter
        wrote on 6 Nov 2020, 06:28 last edited by
        #3

        Well, I don’t want it always on top, and I certainly do not want it frameless, and I need it to be resizable.

        Can you run the example project I provided, and perhaps edit the code to make it work? I’ve done everything I can think of

        it doesn’t seem like QT actually supports transparent windows even though the documentation says that it does?

        1 Reply Last reply
        0
        • J Online
          J Online
          J.Hilk
          Moderators
          wrote on 6 Nov 2020, 06:38 last edited by
          #4

          I didn't see the link 🙈
          Well yes, your way described seems to work, some what, when I moved the window from gpu rendered screen to cpu rendered one it broke completely

          What also works, is FramelessWindowHint & TranslucentBackground

          but you said you don't want frameless 🤔

          Not sure if I can help you :(


          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
          • D Offline
            D Offline
            davecotter
            wrote on 6 Nov 2020, 17:09 last edited by
            #5

            @J-Hilk did you do that on mac or windows? did you use my app to do it? what steps did you take, exactly?

            1 Reply Last reply
            0
            • I Offline
              I Offline
              iamsergio
              wrote on 6 Nov 2020, 18:21 last edited by
              #6

              Qt::WA_TranslucentBackground requires Qt::FramelessWindowHint to work on Windows.

              If that didn't work for you then you are setting the attribute and flag too late. Be sure to call the attributes very early, before show, the first thing you do in the constructor.

              If you decide to go this route then also have a look at QWindow::startSystemResize and QWindow::startSystemMove which might help make this less painful.

              #include <QtWidgets>
              
              class MyWidget : public QWidget
              {
              public:
                  MyWidget()
                  {
                      setAttribute(Qt::WA_TranslucentBackground, true);
                      setWindowFlag(Qt::FramelessWindowHint, true);
              
                      auto lay = new QVBoxLayout(this);
                      lay->setSpacing(10);
                      lay->addWidget(new QPushButton("1"));
                      lay->addWidget(new QPushButton("2"));
                  }
              };
              
              int main(int argc, char *argv[])
              {
                  QApplication app(argc, argv);
                  MyWidget window;
                  window.show();
              
                  return app.exec();
              }
              
              1 Reply Last reply
              3
              • I Offline
                I Offline
                iamsergio
                wrote on 6 Nov 2020, 19:01 last edited by iamsergio 11 Jun 2020, 19:01
                #7

                Let's now see QWidget::setMask(region) instead.
                It's very powerful and doesn't require any special flags, you just set the region that you don't want as transparent.

                The downside is you need to calculate the regions yourself, so I would only use this for simple static layouts.

                Also the title bar looks weird. There might be Win32 API to fix it though.

                screenshot here

                #include <QtWidgets>
                
                // Example of having a window with an hole, but still preserving title bar
                
                class MyWidget : public QWidget
                {
                public:
                    MyWidget()
                    {
                        resize(1000, 1000);
                    }
                
                    void resizeEvent(QResizeEvent *ev) override
                    {
                        QWidget::resizeEvent(ev);
                
                        QRect r = frameGeometry();
                        r.moveTopLeft(mapFromGlobal(r.topLeft()) );
                
                        QRect hole(0, 0, width() - 50, 100);
                        hole.moveCenter(rect().center());
                
                        setMask(QRegion(r).subtracted(hole));
                    }
                };
                
                int main(int argc, char *argv[])
                {
                    QApplication app(argc, argv);
                    MyWidget window;
                    window.show();
                
                    return app.exec();
                }
                
                1 Reply Last reply
                1

                1/7

                6 Nov 2020, 03:24

                • Login

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