Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    QMdiSubWindow with transparency and opacity

    General and Desktop
    transparency opacity qmdisubwindow qmdiarea css
    3
    6
    3122
    Loading More Posts
    • 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.
    • scastiello
      scastiello last edited by

      Hi guys,

      I trying to create new QMdiSubWindow with transparency and opacity to be able to see the background of QMdiArea.

      I try to overwrite paintEvent like this:

      void MdiSubWindow::paintEvent(QPaintEvent *aEvent)
      {
          QPainter painter(this);
          painter.setRenderHint(QPainter::Antialiasing, true);
          painter.setOpacity(0.5);
          painter.setBrush(Qt::red);
          painter.drawRoundedRect(0, 0 , width(), height(), 20.0, 20.0);
      
          // QWidget::paintEvent(aEvent);
      }
      

      And then a in CSS try this:

      QMdiSubWindow {
          border: 1px solid transparent;
          border-radius: 100px;
          opacity: 0.5;
          background: tranparent;
      }
      
      QMdiSubWindow QWidget {
          background: transparent;
      }
      
      QMdiSubWindow:title {
          height: 18px;
          background: transparent;
      }
      
      QMdiSubWindow #accept {
          background: green;
          border: 1px solid #000000;
          margin: 10px;
          border-radius: 5px;
      }
      
      QMdiSubWindow #cancel {
          background: red;
          border: 1px solid #000000;
          margin: 10px;
          border-radius: 5px;
      }
      

      The window look like this:

      Alt text

      But i cant remove the default background of QMdiSubWindow. Can anyone help me?

      Malek_Khlif 1 Reply Last reply Reply Quote 0
      • Malek_Khlif
        Malek_Khlif @scastiello last edited by

        @scastiello You cas use
        setAttribute(Qt::WA_NoBackground);
        setAttribute(Qt::WA_NoSystemBackground);
        setAttribute(Qt::WA_TranslucentBackground);
        setAttribute(Qt::WA_DeleteOnClose);

        in your MdiSubWindow class

        I Love Qt <3

        1 Reply Last reply Reply Quote 2
        • scastiello
          scastiello last edited by

          It works perfectly , thank you very much. :)

          Malek_Khlif 1 Reply Last reply Reply Quote 1
          • Malek_Khlif
            Malek_Khlif @scastiello last edited by

            @scastiello ;)

            I Love Qt <3

            1 Reply Last reply Reply Quote 0
            • SGaist
              SGaist Lifetime Qt Champion last edited by

              Hi,

              @Malek_Khlif said:

              setAttribute(Qt::WA_DeleteOnClose);

              Just beware, that one has nothing to do with painting. Depending on how you handle your mdi sub windows you will have surprises.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply Reply Quote 2
              • Malek_Khlif
                Malek_Khlif last edited by

                Yes of course

                I Love Qt <3

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post