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.1k 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.
  • C Offline
    C Offline
    CodeFreaks
    wrote on 7 Aug 2018, 11:44 last edited by CodeFreaks 8 Jul 2018, 15:22
    #9
    This post is deleted!
    1 Reply Last reply
    0
    • C Offline
      C Offline
      CodeFreaks
      wrote on 7 Aug 2018, 15:23 last edited by CodeFreaks 8 Aug 2018, 06:58
      #10
      This post is deleted!
      1 Reply Last reply
      0
      • C Offline
        C Offline
        CodeFreaks
        wrote on 8 Aug 2018, 06:47 last edited by CodeFreaks 8 Aug 2018, 06:59
        #11

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

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on 8 Aug 2018, 09:46 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();
          }
          
          C 8 J 3 Replies Last reply 20 Sept 2018, 06:54
          10
          • C Chris Kawa
            8 Aug 2018, 09:46

            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();
            }
            
            C Offline
            C Offline
            CodeFreaks
            wrote on 20 Sept 2018, 06:54 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
            • C Chris Kawa
              8 Aug 2018, 09:46

              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();
              }
              
              8 Offline
              8 Offline
              8Observer8
              wrote on 24 Jun 2021, 10:46 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 8 May 2023, 15:31
              1
              • 8 8Observer8
                24 Jun 2021, 10:46

                @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 8 May 2023, 15:31 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?

                8 1 Reply Last reply 30 May 2023, 10:39
                0
                • T Taytoo
                  8 May 2023, 15:31

                  @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?

                  8 Offline
                  8 Offline
                  8Observer8
                  wrote on 30 May 2023, 10:39 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
                  • C Chris Kawa
                    8 Aug 2018, 09:46

                    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();
                    }
                    
                    J Offline
                    J Offline
                    JoeCFD
                    wrote on 22 Apr 2024, 22:56 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

                    J 1 Reply Last reply 23 Apr 2024, 04:19
                    0
                    • J JoeCFD
                      22 Apr 2024, 22:56

                      @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

                      J Offline
                      J Offline
                      JoeCFD
                      wrote on 23 Apr 2024, 04:19 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 23 Apr 2024, 06:16
                      0
                      • J JoeCFD
                        23 Apr 2024, 04:19

                        @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 23 Apr 2024, 06:16 last edited by
                        #19

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

                        J 1 Reply Last reply 23 Apr 2024, 22:56
                        0
                        • Ronel_qtmasterR Ronel_qtmaster
                          23 Apr 2024, 06:16

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

                          J Offline
                          J Offline
                          JoeCFD
                          wrote on 23 Apr 2024, 22:56 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

                          J Ronel_qtmasterR 2 Replies Last reply 24 Apr 2024, 15:33
                          0
                          • J JoeCFD
                            23 Apr 2024, 22:56

                            @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

                            J Offline
                            J Offline
                            JoeCFD
                            wrote on 24 Apr 2024, 15:33 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

                            J 2 Replies Last reply 25 Apr 2024, 14:44
                            0
                            • J JoeCFD
                              23 Apr 2024, 22:56

                              @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 24 Apr 2024, 15:58 last edited by
                              #22

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

                              1 Reply Last reply
                              0
                              • J JoeCFD
                                24 Apr 2024, 15:33

                                @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

                                J Offline
                                J Offline
                                JoeCFD
                                wrote on 25 Apr 2024, 14:44 last edited by
                                #23

                                @JoeCFD The ticket is set to Important.

                                1 Reply Last reply
                                0
                                • J JoeCFD
                                  24 Apr 2024, 15:33

                                  @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

                                  J Offline
                                  J Offline
                                  JoeCFD
                                  wrote on 3 May 2024, 15:09 last edited by JoeCFD 5 Mar 2024, 15:17
                                  #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