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. QMdiSubWindow with transparency and opacity

QMdiSubWindow with transparency and opacity

Scheduled Pinned Locked Moved General and Desktop
transparencyopacityqmdisubwindowqmdiareacss
6 Posts 3 Posters 4.5k Views 2 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.
  • scastielloS Offline
    scastielloS Offline
    scastiello
    wrote on last edited by
    #1

    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_KhlifM 1 Reply Last reply
    0
    • scastielloS scastiello

      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_KhlifM Offline
      Malek_KhlifM Offline
      Malek_Khlif
      wrote on last edited by
      #2

      @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
      2
      • scastielloS Offline
        scastielloS Offline
        scastiello
        wrote on last edited by
        #3

        It works perfectly , thank you very much. :)

        Malek_KhlifM 1 Reply Last reply
        1
        • scastielloS scastiello

          It works perfectly , thank you very much. :)

          Malek_KhlifM Offline
          Malek_KhlifM Offline
          Malek_Khlif
          wrote on last edited by
          #4

          @scastiello ;)

          I Love Qt <3

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            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
            2
            • Malek_KhlifM Offline
              Malek_KhlifM Offline
              Malek_Khlif
              wrote on last edited by
              #6

              Yes of course

              I Love Qt <3

              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