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. Make a maskWidget to grandparent widget
Forum Updated to NodeBB v4.3 + New Features

Make a maskWidget to grandparent widget

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 291 Views 1 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.
  • Joe JohnsonJ Offline
    Joe JohnsonJ Offline
    Joe Johnson
    wrote on last edited by
    #1

    I want to make a mask widget,which is transparent to its parent widget,and mask its grandparent widget.But it seems like that the mask widget isn't able to resize larger than its parent,could you please expand what's wrong?
    20210722204029.png

    //MaskWidget.cpp
    MaskWidget::MaskWidget(QWidget *parent) : QWidget(parent)
    {
        m_pVisibleLabel = new QLabel(this);
        //mask,not transparent
        setStyleSheet("QWidget{background-color:rgba(0,0,255,60%);}");
        //transparent,so that I am able to leave the parent widget visible
        m_pVisibleLabel->setStyleSheet("QLabel{background-color:transparent;}");
    }
    
    void MaskWidget::SyncUI()
    {
        QWidget *pParent = parentWidget();
        if(pParent != nullptr)
        {
            QWidget *pGrandParent = pParent->parentWidget();
            if(pGrandParent != nullptr)
            {
                //mask the grandparent widget,like a mask,but not work
                this->resize(pGrandParent->width(),pGrandParent->height());
                //leave the parent widget visible
                m_pVisibleLabel->resize(pParent->width(),pParent->height());
                QPoint point = mapToParent(QPoint(0,0));
                m_pVisibleLabel->move(point);
            }
        }
    }
    
    //ChildWidget.cpp
    //show the mask whenever the child widget is shown
    void ChildWidget::showEvent(QShowEvent *event)
    {
        m_pMask->show();
        m_pMask->SyncUI();
        m_pMask->raise();
    }
    
    Pl45m4P 1 Reply Last reply
    0
    • Joe JohnsonJ Joe Johnson

      I want to make a mask widget,which is transparent to its parent widget,and mask its grandparent widget.But it seems like that the mask widget isn't able to resize larger than its parent,could you please expand what's wrong?
      20210722204029.png

      //MaskWidget.cpp
      MaskWidget::MaskWidget(QWidget *parent) : QWidget(parent)
      {
          m_pVisibleLabel = new QLabel(this);
          //mask,not transparent
          setStyleSheet("QWidget{background-color:rgba(0,0,255,60%);}");
          //transparent,so that I am able to leave the parent widget visible
          m_pVisibleLabel->setStyleSheet("QLabel{background-color:transparent;}");
      }
      
      void MaskWidget::SyncUI()
      {
          QWidget *pParent = parentWidget();
          if(pParent != nullptr)
          {
              QWidget *pGrandParent = pParent->parentWidget();
              if(pGrandParent != nullptr)
              {
                  //mask the grandparent widget,like a mask,but not work
                  this->resize(pGrandParent->width(),pGrandParent->height());
                  //leave the parent widget visible
                  m_pVisibleLabel->resize(pParent->width(),pParent->height());
                  QPoint point = mapToParent(QPoint(0,0));
                  m_pVisibleLabel->move(point);
              }
          }
      }
      
      //ChildWidget.cpp
      //show the mask whenever the child widget is shown
      void ChildWidget::showEvent(QShowEvent *event)
      {
          m_pMask->show();
          m_pMask->SyncUI();
          m_pMask->raise();
      }
      
      Pl45m4P Online
      Pl45m4P Online
      Pl45m4
      wrote on last edited by Pl45m4
      #2

      @Joe-Johnson said in Make a maskWidget to grandparent widget:

      isn't able to resize larger than its parent,could you please expand what's wrong?

      True. Since the position is displayed in parent's coordinate system, it can't exceed its parent's boundaries.

      What if you "un-parent" it and make it a direct child of its current grandparent?


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      Joe JohnsonJ 1 Reply Last reply
      1
      • Joe JohnsonJ Offline
        Joe JohnsonJ Offline
        Joe Johnson
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • Pl45m4P Pl45m4

          @Joe-Johnson said in Make a maskWidget to grandparent widget:

          isn't able to resize larger than its parent,could you please expand what's wrong?

          True. Since the position is displayed in parent's coordinate system, it can't exceed its parent's boundaries.

          What if you "un-parent" it and make it a direct child of its current grandparent?

          Joe JohnsonJ Offline
          Joe JohnsonJ Offline
          Joe Johnson
          wrote on last edited by
          #4

          @Pl45m4 oops,It works well,thanks.Here is result a01c7252-c384-4aee-8f7b-63071df25dff-image.png

          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