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 Widget
Forum Updated to NodeBB v4.3 + New Features

transparent Widget

Scheduled Pinned Locked Moved Unsolved General and Desktop
24 Posts 7 Posters 19.0k Views 5 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.
  • CodeFreaksC Offline
    CodeFreaksC Offline
    CodeFreaks
    wrote on last edited by CodeFreaks
    #10
    This post is deleted!
    1 Reply Last reply
    0
    • CodeFreaksC Offline
      CodeFreaksC Offline
      CodeFreaks
      wrote on last edited by CodeFreaks
      #11

      I examined many ways,
      But I can't make a transparent tabwidget (In Linux) :
      0_1533655210141_trpr2.png

      1 Reply Last reply
      0
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by Chris Kawa
        #12

        It's a 3 step process.

        1. Make the window widget transparent using attribute Qt::WA_TranslucentBackground, which gives you something like in your picture:
          Transparency step 1

        2. Make the tab header transparent. You can do that with stylesheet QTabBar::tab { background: transparent; }
          Note that this is styling QTabBar, not QTabWidget.
          Transparency step 2
          You can modify the stylesheet to add the borders of the tab back if you like.

        3. Make the tab content transparent. Note that QTabWidget itself doesn't have a background. It's the background of the widget inside it that you need to make transparent. The easiest way to do this is to tell Qt that the paint event takes care of all the painting and it does not need to fill the background with default color i.e. use Qt::WA_OpaquePaintEvent attribute.
          Transparency step 3

        So the entire example looks like this:

        int main(int argc, char *argv[])
        {
            QApplication a(argc, argv);
        
            QWidget* tab_content = new QWidget();
            tab_content->setAttribute(Qt::WA_OpaquePaintEvent); //makes the widget transparent
        
            QTabWidget* tw = new QTabWidget();
            tw->addTab(tab_content, "Example");
            tw->setStyleSheet("QTabBar::tab { background: transparent; }"); //makes the header transparent
        
            QWidget w;
            w.setAttribute(Qt::WA_TranslucentBackground); //makes the window transparent
            w.setLayout(new QVBoxLayout());
            w.layout()->addWidget(tw);
            w.show();
        
            return a.exec();
        }
        
        CodeFreaksC 8Observer88 JoeCFDJ 3 Replies Last reply
        10
        • Chris KawaC Chris Kawa

          It's a 3 step process.

          1. Make the window widget transparent using attribute Qt::WA_TranslucentBackground, which gives you something like in your picture:
            Transparency step 1

          2. Make the tab header transparent. You can do that with stylesheet QTabBar::tab { background: transparent; }
            Note that this is styling QTabBar, not QTabWidget.
            Transparency step 2
            You can modify the stylesheet to add the borders of the tab back if you like.

          3. Make the tab content transparent. Note that QTabWidget itself doesn't have a background. It's the background of the widget inside it that you need to make transparent. The easiest way to do this is to tell Qt that the paint event takes care of all the painting and it does not need to fill the background with default color i.e. use Qt::WA_OpaquePaintEvent attribute.
            Transparency step 3

          So the entire example looks like this:

          int main(int argc, char *argv[])
          {
              QApplication a(argc, argv);
          
              QWidget* tab_content = new QWidget();
              tab_content->setAttribute(Qt::WA_OpaquePaintEvent); //makes the widget transparent
          
              QTabWidget* tw = new QTabWidget();
              tw->addTab(tab_content, "Example");
              tw->setStyleSheet("QTabBar::tab { background: transparent; }"); //makes the header transparent
          
              QWidget w;
              w.setAttribute(Qt::WA_TranslucentBackground); //makes the window transparent
              w.setLayout(new QVBoxLayout());
              w.layout()->addWidget(tw);
              w.show();
          
              return a.exec();
          }
          
          CodeFreaksC Offline
          CodeFreaksC Offline
          CodeFreaks
          wrote on last edited by CodeFreaks
          #13

          @Chris-Kawa
          Hi Dear Chris Kawa
          The method that you mentioned in previous post helped me a lot.
          Thanks a lot.
          But I tried to make a semi-transparent canvas (of qwtplot) . The canvas inherit from QFrame. I tried many days but I still can't do that.
          A black background will appear instead of parent widget behind it.
          QwtPlotCanvas Class Reference

          1 Reply Last reply
          0
          • Chris KawaC Chris Kawa

            It's a 3 step process.

            1. Make the window widget transparent using attribute Qt::WA_TranslucentBackground, which gives you something like in your picture:
              Transparency step 1

            2. Make the tab header transparent. You can do that with stylesheet QTabBar::tab { background: transparent; }
              Note that this is styling QTabBar, not QTabWidget.
              Transparency step 2
              You can modify the stylesheet to add the borders of the tab back if you like.

            3. Make the tab content transparent. Note that QTabWidget itself doesn't have a background. It's the background of the widget inside it that you need to make transparent. The easiest way to do this is to tell Qt that the paint event takes care of all the painting and it does not need to fill the background with default color i.e. use Qt::WA_OpaquePaintEvent attribute.
              Transparency step 3

            So the entire example looks like this:

            int main(int argc, char *argv[])
            {
                QApplication a(argc, argv);
            
                QWidget* tab_content = new QWidget();
                tab_content->setAttribute(Qt::WA_OpaquePaintEvent); //makes the widget transparent
            
                QTabWidget* tw = new QTabWidget();
                tw->addTab(tab_content, "Example");
                tw->setStyleSheet("QTabBar::tab { background: transparent; }"); //makes the header transparent
            
                QWidget w;
                w.setAttribute(Qt::WA_TranslucentBackground); //makes the window transparent
                w.setLayout(new QVBoxLayout());
                w.layout()->addWidget(tw);
                w.show();
            
                return a.exec();
            }
            
            8Observer88 Offline
            8Observer88 Offline
            8Observer8
            wrote on last edited by 8Observer8
            #14

            @Chris-Kawa, I tried your code but it does not work on Windows 10 and Qt 5.15.2. Why? Maybe does somebody else know it?

            75fed7ee-28f7-4f06-bc0e-964e810e3be0-image.png

            T 1 Reply Last reply
            1
            • 8Observer88 8Observer8

              @Chris-Kawa, I tried your code but it does not work on Windows 10 and Qt 5.15.2. Why? Maybe does somebody else know it?

              75fed7ee-28f7-4f06-bc0e-964e810e3be0-image.png

              T Offline
              T Offline
              Taytoo
              wrote on last edited by
              #15

              @8Observer8 Were you able to resolve this issue? I'm having weird behavior even though i'm following the instructions, so not sure what am I doing wrong?

              8Observer88 1 Reply Last reply
              0
              • T Taytoo

                @8Observer8 Were you able to resolve this issue? I'm having weird behavior even though i'm following the instructions, so not sure what am I doing wrong?

                8Observer88 Offline
                8Observer88 Offline
                8Observer8
                wrote on last edited by 8Observer8
                #16

                @Taytoo I am also waiting for a solution. Maybe someone knows what is the problem in the above example?

                How to implement the same behavior as in ScreenToGif to take a screenshot inside a window?

                a0b7471f-1d25-4498-8039-89ebd6a432ca-image.png

                1 Reply Last reply
                0
                • Chris KawaC Chris Kawa

                  It's a 3 step process.

                  1. Make the window widget transparent using attribute Qt::WA_TranslucentBackground, which gives you something like in your picture:
                    Transparency step 1

                  2. Make the tab header transparent. You can do that with stylesheet QTabBar::tab { background: transparent; }
                    Note that this is styling QTabBar, not QTabWidget.
                    Transparency step 2
                    You can modify the stylesheet to add the borders of the tab back if you like.

                  3. Make the tab content transparent. Note that QTabWidget itself doesn't have a background. It's the background of the widget inside it that you need to make transparent. The easiest way to do this is to tell Qt that the paint event takes care of all the painting and it does not need to fill the background with default color i.e. use Qt::WA_OpaquePaintEvent attribute.
                    Transparency step 3

                  So the entire example looks like this:

                  int main(int argc, char *argv[])
                  {
                      QApplication a(argc, argv);
                  
                      QWidget* tab_content = new QWidget();
                      tab_content->setAttribute(Qt::WA_OpaquePaintEvent); //makes the widget transparent
                  
                      QTabWidget* tw = new QTabWidget();
                      tw->addTab(tab_content, "Example");
                      tw->setStyleSheet("QTabBar::tab { background: transparent; }"); //makes the header transparent
                  
                      QWidget w;
                      w.setAttribute(Qt::WA_TranslucentBackground); //makes the window transparent
                      w.setLayout(new QVBoxLayout());
                      w.layout()->addWidget(tw);
                      w.show();
                  
                      return a.exec();
                  }
                  
                  JoeCFDJ Offline
                  JoeCFDJ Offline
                  JoeCFD
                  wrote on last edited by JoeCFD
                  #17

                  @Chris-Kawa Your code works nicely on my local computer. But the transparent feature is gone after I copy the executable from my machine to another computer. Any thoughts?

                  same OS: Ubuntu 22.04
                  same Qt version: 5.15.3

                  JoeCFDJ 1 Reply Last reply
                  0
                  • JoeCFDJ JoeCFD

                    @Chris-Kawa Your code works nicely on my local computer. But the transparent feature is gone after I copy the executable from my machine to another computer. Any thoughts?

                    same OS: Ubuntu 22.04
                    same Qt version: 5.15.3

                    JoeCFDJ Offline
                    JoeCFDJ Offline
                    JoeCFD
                    wrote on last edited by JoeCFD
                    #18

                    @JoeCFD I lied. The desktop is different. One is gnome and another one is lxqt. It could be a qt bug.

                    Ronel_qtmasterR 1 Reply Last reply
                    0
                    • JoeCFDJ JoeCFD

                      @JoeCFD I lied. The desktop is different. One is gnome and another one is lxqt. It could be a qt bug.

                      Ronel_qtmasterR Offline
                      Ronel_qtmasterR Offline
                      Ronel_qtmaster
                      wrote on last edited by
                      #19

                      @JoeCFD you people may find this helpfull
                      https://github.com/jordanprog86/QtTransparentWindow.git
                      tw.PNG

                      JoeCFDJ 1 Reply Last reply
                      0
                      • Ronel_qtmasterR Ronel_qtmaster

                        @JoeCFD you people may find this helpfull
                        https://github.com/jordanprog86/QtTransparentWindow.git
                        tw.PNG

                        JoeCFDJ Offline
                        JoeCFDJ Offline
                        JoeCFD
                        wrote on last edited by JoeCFD
                        #20

                        @Ronel_qtmaster thanks for your post. Your code is not working on Lubuntu with LXQt desktop as well for Qt5/6. Chris Kawa's test code has the same issue.

                        The following example works
                        https://doc.qt.io/qt-5/qtwidgets-widgets-shapedclock-example.html

                        JoeCFDJ Ronel_qtmasterR 2 Replies Last reply
                        0
                        • JoeCFDJ JoeCFD

                          @Ronel_qtmaster thanks for your post. Your code is not working on Lubuntu with LXQt desktop as well for Qt5/6. Chris Kawa's test code has the same issue.

                          The following example works
                          https://doc.qt.io/qt-5/qtwidgets-widgets-shapedclock-example.html

                          JoeCFDJ Offline
                          JoeCFDJ Offline
                          JoeCFD
                          wrote on last edited by JoeCFD
                          #21

                          @JoeCFD solved the transparency issue in my code with mask. but kind of awkward and unnecessary. Submit a bug report with Chris Kawa's test code here
                          https://bugreports.qt.io/browse/QTBUG-124722

                          JoeCFDJ 2 Replies Last reply
                          0
                          • JoeCFDJ JoeCFD

                            @Ronel_qtmaster thanks for your post. Your code is not working on Lubuntu with LXQt desktop as well for Qt5/6. Chris Kawa's test code has the same issue.

                            The following example works
                            https://doc.qt.io/qt-5/qtwidgets-widgets-shapedclock-example.html

                            Ronel_qtmasterR Offline
                            Ronel_qtmasterR Offline
                            Ronel_qtmaster
                            wrote on last edited by
                            #22

                            @JoeCFD i think on ubuntu it might depend on the windows manager

                            1 Reply Last reply
                            0
                            • JoeCFDJ JoeCFD

                              @JoeCFD solved the transparency issue in my code with mask. but kind of awkward and unnecessary. Submit a bug report with Chris Kawa's test code here
                              https://bugreports.qt.io/browse/QTBUG-124722

                              JoeCFDJ Offline
                              JoeCFDJ Offline
                              JoeCFD
                              wrote on last edited by
                              #23

                              @JoeCFD The ticket is set to Important.

                              1 Reply Last reply
                              0
                              • JoeCFDJ JoeCFD

                                @JoeCFD solved the transparency issue in my code with mask. but kind of awkward and unnecessary. Submit a bug report with Chris Kawa's test code here
                                https://bugreports.qt.io/browse/QTBUG-124722

                                JoeCFDJ Offline
                                JoeCFDJ Offline
                                JoeCFD
                                wrote on last edited by JoeCFD
                                #24

                                @JoeCFD My solution with mask for transparency works for LXQt desktop, but not for Gnome Desktop of Ubuntu. Reset of mask regions is wrong sometimes. Added this issue to the bug report.

                                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