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

QMdiSubWindow with transparency and opacity

Scheduled Pinned Locked Moved General and Desktop
transparencyopacityqmdisubwindowqmdiareacss
6 Posts 3 Posters 4.0k 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.
  • S Offline
    S Offline
    scastiello
    wrote on 12 Mar 2015, 08:17 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?

    M 1 Reply Last reply 12 Mar 2015, 08:28
    0
    • S scastiello
      12 Mar 2015, 08:17

      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?

      M Offline
      M Offline
      Malek_Khlif
      wrote on 12 Mar 2015, 08:28 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
      • S Offline
        S Offline
        scastiello
        wrote on 12 Mar 2015, 09:14 last edited by
        #3

        It works perfectly , thank you very much. :)

        M 1 Reply Last reply 12 Mar 2015, 15:18
        1
        • S scastiello
          12 Mar 2015, 09:14

          It works perfectly , thank you very much. :)

          M Offline
          M Offline
          Malek_Khlif
          wrote on 12 Mar 2015, 15:18 last edited by
          #4

          @scastiello ;)

          I Love Qt <3

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 12 Mar 2015, 22:10 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
            • M Offline
              M Offline
              Malek_Khlif
              wrote on 13 Mar 2015, 07:19 last edited by
              #6

              Yes of course

              I Love Qt <3

              1 Reply Last reply
              0

              1/6

              12 Mar 2015, 08:17

              • Login

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