场景描述如下:
class QM : public QMenu
{
Q_OBJECT
public:
QM(QString title = "", QWidget* parent=nullptr):QMenu(title,parent)
{
setWindowFlags(windowFlags() | Qt::NoDropShadowWindowHint |Qt::FramelessWindowHint);
setAttribute(Qt::WA_TranslucentBackground);
QString qs = R"(
QMenu::item
{
background-color: #ffffff;
min-height:100px;
}
QMenu{
background-color: rgb(255, 255, 255);
border-radius: 14px;
padding:10px 10px 10px 10px;
border:1px solid #cccccc;
}
QMenu::right-arrow
{
image: url(:/DpiDemo/menuRightArray.png);
padding-right:10px;
width:8px;
height:8px;
}
QMenu::indicator:non-exclusive:checked {
image: url(:/DpiDemo/menuChecked.png);
width:20px;
height:20px;
margin-right:10px;
}
QMenu::indicator:non-exclusive:unchecked {
width:20px;
height:20px;
margin-right:10px;
}
QMenu::item:selected:!disabled
{
background-color: rgb(229,247,236);
background-clip:padding;
border: 1px solid rgb(172, 230, 195);
border-radius: 4px;
}
QMenu::separator
{
background-color:rgb(209, 209, 209);
height:1px;
}
)";
setStyleSheet(qs);
QFont font;
font.setFamily("Microsoft YaHei");
font.setPixelSize(15);
setFont(font);
setPalette(Qt::white);
}
};
int main()
{
QMenu menu;
auto a2 = menu.addAction("New &Ta34tg...");
a2->setCheckable(true);
a2->setChecked(false);
auto a = menu.addAction("&Ed34t34it");
a->setCheckable(true);
a->setChecked(true);
auto n = menu.addAction("save f34t34t34ile(&s)");
n->setCheckable(true);
n->setChecked(false);
n->setDisabled(true);
QM *menus = new QM("sort by reverssdafasdfe sdaf34t43tasdf", &menu);
menus->addAction("New &Tag...");
menus->addAction("&Edit file\tCtrl+E");
menus->addAction("save file(&s)");
auto q = menu.addMenu(menus);
q->setCheckable(true);
}
注:其中代码仅核心代码,无法直接拷贝运行
在你的截图中QMenu::item中你是设置了margin-top,但是你的你重合的部分在右侧,你可以加上margin-right:xxpx;进行尝试