Solved Make a maskWidget to grandparent widget
-
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?
//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(); }
-
@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-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?
-
This post is deleted! -
@Pl45m4 oops,It works well,thanks.Here is result