我正在使用
QFrame
创建圆形上下文菜单。
为了制作圆角,我使用了 Qt 样式表:
this->setStyleSheet("QFrame#ShareContextMenu{
background-color:rgb(255,255,255);
border-width:1px;
border-color :rgb(0,0,0);
border-radius:10px;
border-style:solid;}
QPushButton{background-color:rgba(255,255,255,0);}
QPushButton::hover{background-color:rgba(125,125,125,50); border-radius:5px;}");
如何去除图中标有红色圆圈的白色背景?
我认为您无法使用样式表解决该问题。
QMenu
是一个矩形顶级小部件。
this
是你的QMenu
吗?如果是这样,请尝试以下操作:
this->setWindowFlags(this->windowFlags() | Qt::FramelessWindowHint);
this->setAttribute(Qt::WA_TranslucentBackground);
将
this
替换为实例化的 QMenu
对象。
当然,你也可以使用setMask来隐藏所需的区域。例如:
QRegion region (menu->x(),
menu->y(),
menu->sizeHint().width(),
menu->sizeHint().height(),
QRegion::Ellipse);
menu->setMask(region);